Skip to content

Commit

Permalink
Add a debugging mode controlled by NEXTSTRAIN_DEBUG
Browse files Browse the repository at this point in the history
At the moment, this only enables printing of stack traces and the full
exception chain for handled (i.e. anticipated) errors, which otherwise
were not printed.  In the future, this mode can also control the output
of verbose debugging/troubleshooting logging for more commands.

Related to <#201>.
  • Loading branch information
tsibley committed Jul 27, 2022
1 parent 72500a8 commit 229f2e8
Show file tree
Hide file tree
Showing 2 changed files with 17 additions and 1 deletion.
6 changes: 5 additions & 1 deletion nextstrain/cli/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand All @@ -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:
Expand Down
12 changes: 12 additions & 0 deletions nextstrain/cli/debug.py
Original file line number Diff line number Diff line change
@@ -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"))

0 comments on commit 229f2e8

Please sign in to comment.