diff --git a/CHANGES.md b/CHANGES.md index dc68fe70..42abdb87 100644 --- a/CHANGES.md +++ b/CHANGES.md @@ -13,6 +13,16 @@ development source code and as such may not be routinely kept up to date. # __NEXT__ +## Development + +* A new debugging mode can be enabled by setting the `NEXTSTRAIN_DEBUG` + environment variable to `1` (or another truthy value). Currently the only + effect is to print more information about handled (i.e. anticipated) errors. + For example, stack traces and parent exceptions in an exception chain are + normally omitted for handled errors, but setting this env var includes them. + Future debugging and troubleshooting features, like verbose operation + logging, will likely also condition on this new debugging mode. + # 4.1.1 (18 July 2022) diff --git a/nextstrain/cli/__init__.py b/nextstrain/cli/__init__.py index 803017ee..674bff76 100644 --- a/nextstrain/cli/__init__.py +++ b/nextstrain/cli/__init__.py @@ -15,6 +15,7 @@ from .argparse import HelpFormatter, register_commands, register_default_command from .command import build, view, deploy, remote, shell, update, check_setup, login, logout, whoami, version, debugger +from .debug import DEBUGGING from .errors import NextstrainCliError from .util import warn from .__version__ import __version__ # noqa: F401 (for re-export) @@ -32,7 +33,10 @@ def run(args): return opts.__command__.run(opts) except NextstrainCliError as error: - warn(error) + if DEBUGGING: + traceback.print_exc() + else: + warn(error) return 1 except AssertionError: diff --git a/nextstrain/cli/debug.py b/nextstrain/cli/debug.py new file mode 100644 index 00000000..56f13abb --- /dev/null +++ b/nextstrain/cli/debug.py @@ -0,0 +1,12 @@ +""" +Debug flags and utilities. + +.. envvar:: NEXTSTRAIN_DEBUG + + Set to a truthy value (e.g. 1) to print more information about (handled) + errors. For example, when this is not set or falsey, stack traces and + parent exceptions in an exception chain are omitted from handled errors. +""" +from os import environ + +DEBUGGING = bool(environ.get("NEXTSTRAIN_DEBUG"))