diff --git a/CHANGELOG.md b/CHANGELOG.md index 8ba0c49..145bd1e 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -1,6 +1,7 @@ # CHANGELOG ## 0.2.14dev +* [Fix] Fix error when using `@modify_exceptions` in an exception initialized without arguments ## 0.2.13 (2023-06-27) diff --git a/src/ploomber_core/exceptions.py b/src/ploomber_core/exceptions.py index dba8cf1..301c304 100644 --- a/src/ploomber_core/exceptions.py +++ b/src/ploomber_core/exceptions.py @@ -82,7 +82,9 @@ class ValidationError(BaseException): def _add_community_link(e): - if COMMUNITY not in e.args[0]: + if not len(e.args): + e.args = (COMMUNITY,) + elif COMMUNITY not in e.args[0]: message = e.args[0] + COMMUNITY e.args = (message,) diff --git a/tests/test_exceptions.py b/tests/test_exceptions.py index 0c72c63..2cad3df 100644 --- a/tests/test_exceptions.py +++ b/tests/test_exceptions.py @@ -65,6 +65,17 @@ def crash(): assert exceptions.get_community_link() in str(excinfo.value) +def test_modify_exceptions_no_message(): + @exceptions.modify_exceptions + def crash(): + raise ValueError + + with pytest.raises(ValueError) as excinfo: + crash() + + assert exceptions.get_community_link() in str(excinfo.value) + + def test_modify_exceptions_value_error_method(): class Something: @exceptions.modify_exceptions