feat: support reraising with error cause

This commit is contained in:
David 2024-06-01 14:56:26 +02:00
parent c770c8e216
commit 153d7cb7a3
No known key found for this signature in database
GPG key ID: AB15A6AF1101390D

View file

@ -296,16 +296,18 @@ def get_traceback(with_context=False) -> str:
"""Return the traceback of the Exception."""
from traceback_with_variables import iter_exc_lines
exc_type, exc_value, exc_tb = sys.exc_info()
if not any([exc_type, exc_value, exc_tb]):
exc = sys.exception()
if not exc:
return ""
if exc.__cause__:
exc = exc.__cause__
if with_context:
trace_list = iter_exc_lines(fmt=_get_traceback_sanitizer())
trace_list = iter_exc_lines(exc, fmt=_get_traceback_sanitizer())
tb = "\n".join(trace_list)
else:
trace_list = traceback.format_exception(exc_type, exc_value, exc_tb)
trace_list = traceback.format_exception(exc)
tb = "".join(cstr(t) for t in trace_list)
bench_path = get_bench_path() + "/"