Skip to content

Commit 52ee9f8

Browse files
committed
pass message through to replaced exception
1 parent 386863e commit 52ee9f8

File tree

3 files changed

+4
-3
lines changed

3 files changed

+4
-3
lines changed

eth_utils/decorators.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -114,7 +114,7 @@ def wrapper(
114114
return to_wrap(*args, **kwargs)
115115
except old_exceptions as err:
116116
try:
117-
raise old_to_new_exceptions[type(err)] from err
117+
raise old_to_new_exceptions[type(err)](err) from err
118118
except KeyError:
119119
raise TypeError(
120120
"could not look up new exception to use for %r" % err

newsfragments/198.bugfix.rst

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
Pass context to new exception in ``replace_exceptions`` decorator.

tests/decorator-utils/test_replace_exceptions.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@
77
def mock_function_with_exception(old_to_new):
88
@replace_exceptions(old_to_new)
99
def function_with_exception(x):
10-
raise TypeError
10+
raise TypeError("Boom!")
1111

1212
return function_with_exception
1313

@@ -21,5 +21,5 @@ def function_with_exception(x):
2121
),
2222
)
2323
def test_decorator_replaces_exceptions(mock_function_with_exception, old_to_new, new):
24-
with pytest.raises(new):
24+
with pytest.raises(new, match="Boom!"):
2525
mock_function_with_exception(old_to_new)

0 commit comments

Comments
 (0)