Skip to content

Commit

Permalink
Add trace back to log_panic
Browse files Browse the repository at this point in the history
  • Loading branch information
olekli committed Oct 16, 2024
1 parent 6b25379 commit be41282
Show file tree
Hide file tree
Showing 3 changed files with 19 additions and 5 deletions.
2 changes: 1 addition & 1 deletion drresult/logging.py
Original file line number Diff line number Diff line change
Expand Up @@ -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
2 changes: 1 addition & 1 deletion pyproject.toml
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
[tool.poetry]
name = "DrResult"
version = "0.6.1"
version = "0.6.2"
description = ""
authors = ["Ole Kliemann <mail@olekliemann.de>"]
license = "MIT"
Expand Down
20 changes: 17 additions & 3 deletions test/test_traceback.py
Original file line number Diff line number Diff line change
Expand Up @@ -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):
Expand Down

0 comments on commit be41282

Please sign in to comment.