-
Notifications
You must be signed in to change notification settings - Fork 128
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 a debug mode to print stack trace for exceptions caught by top-level handler #1308
Comments
One nice way is to use exception chaining. try:
some_code()
except ConcreteException as e:
raise FinalError(f"There was a concrete error and here is some recommendations: ...") from e (notice I think this is the recommended way to express causality of errors in Python nowadays. The default handler then prints all errors in the chain, with stacks, so there's no need for handcrafted solutions. Perhaps the default handler printout not as nice, but then the custom handler can also be augmented with understanding chains. I am not sure when it was introduced though and so what's the minimum Python version requirement. |
Yes, exceptions should be chained (except in rare cases), and the default handler should know how to emit the full chain with all the gory details when a debug or verbosity flag is set. This is what Nextstrain CLI does, for example. In a case where you couldn't (or didn't want to) just modify the source, you could use the debugger. |
It sounds like the missing piece here is a debug/verbosity flag. Right now the stack trace is only printed on unhandled exceptions because we definitely want that in an issue report. With errors such as With
|
@victorlin unfinished comment? I'd recommend the debug flag live in the environment rather than a command-line option, as it makes it much easier to set in a wide variety of contexts (e.g. places you can't easily control the command-line invocation) and doesn't have issues of not applying before option parsing. |
@tsibley oops, fixed! That sounds reasonable. I'd think to basically mirror what you did in nextstrain/cli#208. |
@victorlin There are two types of tree time error: |
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. Commit contents and message based on similar commits I made to Nextstrain CLI.¹ Resolves <#1308>. ¹ <nextstrain/cli@229f2e8> <nextstrain/cli@b6d9290> <nextstrain/cli#208>
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. Commit contents and message based on similar commits I made to Nextstrain CLI.¹ Resolves <#1308>. ¹ <nextstrain/cli@229f2e8> <nextstrain/cli@b6d9290> <nextstrain/cli#208>
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. Commit contents and message based on similar commits I made to Nextstrain CLI.¹ Resolves <#1308>. ¹ <nextstrain/cli@229f2e8> <nextstrain/cli@b6d9290> <nextstrain/cli#208>
I got this error from refine that I struggled to debug:
Turns out, my sequences weren't aligned, they had different lengths. I'll try to improve treetime's error message, see neherlab/treetime#258.
But while debugging and trying to find out what went wrong, I got quite frustrated by how hard it was to get a stacktrace of how the error originated. (Maybe @tsibley has some clues on how one can get a stacktrace here in this case without having to change any code, maybe some ENV variable trick?)
I think one problem is that we just blanket wrap all treetime errors and discard the stacktrace. Maybe we print the stack trace behind a verbosity flag here, i.e. add
traceback.print_exc(file=sys.stderr)
but only when-v
is passed.augur/augur/__init__.py
Lines 76 to 92 in 854dc7d
The text was updated successfully, but these errors were encountered: