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

Show full stack trace in error messages/logs #30

Merged
merged 4 commits into from
Apr 29, 2021
Merged

Show full stack trace in error messages/logs #30

merged 4 commits into from
Apr 29, 2021

Conversation

ehusby
Copy link
Contributor

@ehusby ehusby commented Apr 28, 2021

When an exception is handled like this:

try:
    some_function()
except RuntimeError as e:
    logger.error(e)

it can be difficult to troubleshoot the error when the error message e isn't helpful on its own.
(It's best to avoid catching the generic RuntimeError (or Exception) whenever possible, and catch a more specific type of error that you know the code might throw.)

If you don't want the code to re-raise the exception after printing out the error message, you can make use of the function traceback.print_exec() to print the full error trace when that would be helpful. The new utils.capture_error_trace() function is helpful in that it capture the output of traceback.print_exec() in a variable, which we can then hand off to logger.error().

@ehusby ehusby merged commit f8f8a3f into master Apr 29, 2021
@ehusby ehusby deleted the erik-dev branch May 14, 2021 23:32
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants