From be412827677e03665eced1c0c84c521cd33b4caf Mon Sep 17 00:00:00 2001 From: Ole Kliemann Date: Wed, 16 Oct 2024 07:59:41 +0000 Subject: [PATCH] Add trace back to log_panic --- drresult/logging.py | 2 +- pyproject.toml | 2 +- test/test_traceback.py | 20 +++++++++++++++++--- 3 files changed, 19 insertions(+), 5 deletions(-) diff --git a/drresult/logging.py b/drresult/logging.py index 7197a06..dadae7d 100644 --- a/drresult/logging.py +++ b/drresult/logging.py @@ -13,5 +13,5 @@ def log_panic(logger: logging.Logger): with gather_result(expects=[], not_expects=[BaseException]) as result: yield except Panic as e: - logger.critical(f'{e}') + logger.critical(f'{e.trace()}') raise diff --git a/pyproject.toml b/pyproject.toml index 084da2f..6cb898c 100644 --- a/pyproject.toml +++ b/pyproject.toml @@ -1,6 +1,6 @@ [tool.poetry] name = "DrResult" -version = "0.6.1" +version = "0.6.2" description = "" authors = ["Ole Kliemann "] license = "MIT" diff --git a/test/test_traceback.py b/test/test_traceback.py index f6a0eca..1f2056f 100644 --- a/test/test_traceback.py +++ b/test/test_traceback.py @@ -143,13 +143,27 @@ def __init__(self): def critical(self, msg): self.msg = msg + @returns_result() + def f1(): + return f2().unwrap_or_raise() + + @returns_result() + def f2(): + return f3().unwrap_or_raise() + + @returns_result() + def f3(): + a = {} + raise SystemError('foo') + a['bar'] = 'baz' + logger = DummyLogger() with pytest.raises(Panic): with log_panic(logger): - result = Err(KeyError('foo')) - result.unwrap_or_raise() + f1() assert logger.msg - assert 'KeyError' in logger.msg and 'foo' in logger.msg + assert 'SystemError' in logger.msg and 'foo' in logger.msg + assert 'f3' in logger.msg and 'f2' in logger.msg and 'f1' in logger.msg def test_excepthook(capsys):