more context in exceptions

This commit is contained in:
ed 2021-07-11 01:59:07 +02:00
parent f757623ad8
commit bfa9f535aa

View file

@ -284,13 +284,11 @@ def alltrace():
def min_ex(): def min_ex():
et, ev, tb = sys.exc_info() et, ev, tb = sys.exc_info()
tb = traceback.extract_tb(tb, 2) tb = traceback.extract_tb(tb)
ex = [ fmt = "{} @ {} <{}>: {}"
"{} @ {} <{}>: {}".format(fp.split(os.sep)[-1], ln, fun, txt) ex = [fmt.format(fp.split(os.sep)[-1], ln, fun, txt) for fp, ln, fun, txt in tb]
for fp, ln, fun, txt in tb ex.append("[{}] {}".format(et.__name__, ev))
] return "\n".join(ex[-8:])
ex.append("{}: {}".format(et.__name__, ev))
return "\n".join(ex)
@contextlib.contextmanager @contextlib.contextmanager