Skip to content

Commit

Permalink
Merge pull request #195 from opensafely-core/more-user-friendly-errors
Browse files Browse the repository at this point in the history
fix: hide traceback from users by default
  • Loading branch information
bloodearnest authored Mar 2, 2023
2 parents 849a68b + b006b99 commit ea30d6f
Showing 1 changed file with 17 additions and 1 deletion.
18 changes: 17 additions & 1 deletion opensafely/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -61,6 +61,13 @@ def show_help(**kwargs):
parser.add_argument(
"--version", action="version", version=f"opensafely {__version__}"
)
parser.add_argument(
"--debug",
"-d",
dest="global_debug",
action="store_true",
help="display debugging information",
)

subparsers = parser.add_subparsers(
title="available commands", description="", metavar="COMMAND"
Expand Down Expand Up @@ -109,7 +116,16 @@ def add_subcommand(cmd, module):
kwargs = vars(args)

function = kwargs.pop("function")
success = function(**kwargs)
debug = kwargs.pop("global_debug")

try:
success = function(**kwargs)
except Exception as exc:
if debug:
raise
else:
print(str(exc), file=sys.stderr)
success = False

# if `run`ning locally, run `check` in warn mode
if function == local_run.main and "format-output-for-github" not in kwargs:
Expand Down

0 comments on commit ea30d6f

Please sign in to comment.