Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add --show-traceback CLI option #365

Merged
merged 3 commits into from
Jan 15, 2019
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions python/CHANGELOG.D/365.feature
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
Implement --show-traceback command line option to show python traceback in case of top-level error
1 change: 1 addition & 0 deletions python/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -60,6 +60,7 @@ Name | Description|
|_\-u, --url URL_|Override API URL \[default: https://platform.dev.neuromation.io/api/v1]|
|_\-t, --token TOKEN_|API authentication token \(not implemented)|
|_--verbose_|Enable verbose logging|
|_\--show-traceback_|Show Python traceback on exception|
|_\-v, --version_|Print version and exit|


Expand Down
36 changes: 22 additions & 14 deletions python/neuromation/cli/main.py
Original file line number Diff line number Diff line change
Expand Up @@ -73,7 +73,7 @@ def setup_console_handler(handler, verbose, noansi=False):


@command
def neuro(url, token, verbose, version):
def neuro(url, token, verbose, show_traceback, version):
""" ◣
▇ ◣
▇ ◥ ◣
Expand All @@ -92,6 +92,7 @@ def neuro(url, token, verbose, version):
-u, --url URL Override API URL [default: {api_url}]
-t, --token TOKEN API authentication token (not implemented)
--verbose Enable verbose logging
--show-traceback Show Python traceback on exception
-v, --version Print version and exit

Commands:
Expand Down Expand Up @@ -883,6 +884,13 @@ def main():
if is_verbose:
sys.argv.remove("--verbose")

is_show_traceback = "--show-traceback" in sys.argv
if is_show_traceback:
sys.argv.remove("--show-traceback")
log_error = log.exception
else:
log_error = log.error

setup_logging()
setup_console_handler(console_handler, verbose=is_verbose)

Expand All @@ -906,51 +914,51 @@ def main():
print(res)

except neuromation.client.IllegalArgumentError as error:
log.error(f"Illegal argument(s) ({error})")
log_error(f"Illegal argument(s) ({error})")
sys.exit(os.EX_DATAERR)

except neuromation.client.ResourceNotFound as error:
log.error(f"{error}")
log_error(f"{error}")
sys.exit(os.EX_OSFILE)

except neuromation.client.AuthenticationError as error:
log.error(f"Cannot authenticate ({error})")
log_error(f"Cannot authenticate ({error})")
sys.exit(os.EX_NOPERM)
except neuromation.client.AuthorizationError as error:
log.error(f"You haven`t enough permission ({error})")
log_error(f"You haven`t enough permission ({error})")
sys.exit(os.EX_NOPERM)

except neuromation.client.ClientError as error:
log.error(f"Application error ({error})")
log_error(f"Application error ({error})")
sys.exit(os.EX_SOFTWARE)

except aiohttp.ClientError as error:
log.error(f"Connection error ({error})")
log_error(f"Connection error ({error})")
sys.exit(os.EX_IOERR)

except NotImplementedError as error:
log.error(f"{error}")
log_error(f"{error}")
sys.exit(os.EX_SOFTWARE)
except FileNotFoundError as error:
log.error(f"File not found ({error})")
log_error(f"File not found ({error})")
sys.exit(os.EX_OSFILE)
except NotADirectoryError as error:
log.error(f"{error}")
log_error(f"{error}")
sys.exit(os.EX_OSFILE)
except PermissionError as error:
log.error(f"Cannot access file ({error})")
log_error(f"Cannot access file ({error})")
sys.exit(os.EX_NOPERM)
except IOError as error:
log.error(f"I/O Error ({error})")
log_error(f"I/O Error ({error})")
raise error

except KeyboardInterrupt:
log.error("Aborting.")
log_error("Aborting.")
sys.exit(130)
except ValueError as e:
print(e)
sys.exit(127)

except Exception as e:
log.error(f"{e}")
log_error(f"{e}")
raise e
2 changes: 1 addition & 1 deletion python/tests/cli/test_help.py
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ def test_help(run):
assert not captured.err
assert captured.out == neuro.__doc__ + "\n"

commands = neuro(None, None, None, None)
commands = neuro(None, None, None, None, None)

for command, func in commands.items():
if not hasattr(func, "_command_name"):
Expand Down