diff --git a/src/ape/exceptions.py b/src/ape/exceptions.py index 04badd8afe..c26ee6eca5 100644 --- a/src/ape/exceptions.py +++ b/src/ape/exceptions.py @@ -305,7 +305,6 @@ def __init__( ): self.txn = txn self.contract_address = contract_address - super().__init__( base_err=base_err, contract_address=contract_address, @@ -316,8 +315,7 @@ def __init__( trace=trace, txn=txn, ) - - if revert_message is None and source_traceback is not None and (dev := self.dev_message): + if not revert_message and source_traceback is not None and (dev := self.dev_message): try: # Attempt to use dev message as main exception message. self.message = dev diff --git a/tests/functional/test_exceptions.py b/tests/functional/test_exceptions.py index 8007b902fc..55f3ca9d36 100644 --- a/tests/functional/test_exceptions.py +++ b/tests/functional/test_exceptions.py @@ -1,5 +1,6 @@ import re from pathlib import Path +from typing import Optional import pytest @@ -11,6 +12,7 @@ TransactionError, handle_ape_exception, ) +from ape.types import SourceTraceback from ape_ethereum.transactions import DynamicFeeTransaction, Receipt @@ -207,3 +209,18 @@ def test_handle_ape_exception_hides_home_dir(mocker): # We expect the same only the home dir has been hidden. expected = "\n" + tb_str.replace(str(Path.home()), "$HOME") assert actual == expected + + +class TestContractLogicError: + @pytest.mark.parametrize("revert_message", (None, "")) + def test_message_uses_revert_type_when_no_revert_message(self, mocker, revert_message): + class TB(SourceTraceback): + @property + def revert_type(self) -> Optional[str]: + return "CUSTOM_ERROR" + + tb = TB([{"statements": [], "closure": {"name": "fn"}, "depth": 0}]) # type: ignore + error = ContractLogicError(revert_message=revert_message, source_traceback=tb) + actual = error.message + expected = "CUSTOM_ERROR" + assert actual == expected