PolarGeospatialCenter / imagery_utils

Other
34 stars 10 forks source link

Show full stack trace in error messages/logs #30

Closed ehusby closed 3 years ago

ehusby commented 3 years ago

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().