Skip to content

Commit

Permalink
check for message attribute (#81)
Browse files Browse the repository at this point in the history
* check for message

* test

* comment
  • Loading branch information
neelasha23 authored Dec 12, 2023
1 parent 6f20b6b commit 2066d88
Show file tree
Hide file tree
Showing 2 changed files with 22 additions and 0 deletions.
5 changes: 5 additions & 0 deletions src/ploomber_core/exceptions.py
Original file line number Diff line number Diff line change
Expand Up @@ -87,6 +87,11 @@ def _add_community_link(e):
elif COMMUNITY not in e.args[0]:
message = e.args[0] + COMMUNITY
e.args = (message,)
# Certain exceptions like ClickException have message
# as their first parameter. In that case args is not
# accessed while raising the error
if hasattr(e, "message"):
e.message = message

return e

Expand Down
17 changes: 17 additions & 0 deletions tests/test_exceptions.py
Original file line number Diff line number Diff line change
Expand Up @@ -54,6 +54,23 @@ def crash():
assert exceptions.get_community_link() in str(excinfo.value)


def test_modify_exceptions_with_message_attribute():
class CustomException(Exception):
def __init__(self, message: str) -> None:
super().__init__(message)
self.message = message
self.modify_exception = True

@exceptions.modify_exceptions
def crash():
raise CustomException("some message")

with pytest.raises(CustomException) as excinfo:
crash()

assert exceptions.get_community_link() in str(excinfo.value)


def test_modify_exceptions_value_error():
@exceptions.modify_exceptions
def crash():
Expand Down

0 comments on commit 2066d88

Please sign in to comment.