From b69d402dc503a0d38381bfa0fcd6dd5829e92775 Mon Sep 17 00:00:00 2001 From: Scott Gasch Date: Fri, 8 Apr 2022 06:54:04 -0700 Subject: [PATCH] Cause the custom exception handler to also log unhandled exceptions' tracebacks. --- bootstrap.py | 8 +++++++- 1 file changed, 7 insertions(+), 1 deletion(-) diff --git a/bootstrap.py b/bootstrap.py index 1174686..a4923b4 100644 --- a/bootstrap.py +++ b/bootstrap.py @@ -98,9 +98,15 @@ def handle_uncaught_exception(exc_type, exc_value, exc_tb): ORIGINAL_EXCEPTION_HOOK(exc_type, exc_value, exc_tb) else: # a terminal is attached and stderr is not redirected, maybe debug. + import io import traceback - traceback.print_exception(exc_type, exc_value, exc_tb) + tb_output = io.StringIO() + traceback.print_tb(exc_tb, None, tb_output) + print(tb_output.getvalue(), file=sys.stderr) + logger.error(tb_output.getvalue()) + tb_output.close() + if config.config['debug_unhandled_exceptions']: import pdb -- 2.46.0