Skip to content

Commit f0d346a

Browse files
committed
Fix error when using @modify_exceptions in an exception initialized without arguments
1 parent fd1fa92 commit f0d346a

File tree

3 files changed

+15
-1
lines changed

3 files changed

+15
-1
lines changed

CHANGELOG.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
# CHANGELOG
22

33
## 0.2.14dev
4+
* [Fix] Fix error when using `@modify_exceptions` in an exception initialized without arguments
45

56
## 0.2.13 (2023-06-27)
67

src/ploomber_core/exceptions.py

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -82,7 +82,9 @@ class ValidationError(BaseException):
8282

8383

8484
def _add_community_link(e):
85-
if COMMUNITY not in e.args[0]:
85+
if not len(e.args):
86+
e.args = (COMMUNITY,)
87+
elif COMMUNITY not in e.args[0]:
8688
message = e.args[0] + COMMUNITY
8789
e.args = (message,)
8890

tests/test_exceptions.py

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -65,6 +65,17 @@ def crash():
6565
assert exceptions.get_community_link() in str(excinfo.value)
6666

6767

68+
def test_modify_exceptions_no_message():
69+
@exceptions.modify_exceptions
70+
def crash():
71+
raise ValueError
72+
73+
with pytest.raises(ValueError) as excinfo:
74+
crash()
75+
76+
assert exceptions.get_community_link() in str(excinfo.value)
77+
78+
6879
def test_modify_exceptions_value_error_method():
6980
class Something:
7081
@exceptions.modify_exceptions

0 commit comments

Comments
 (0)