Skip to content

Commit

Permalink
fix: issue detecting proper message from certain virtual machine erro…
Browse files Browse the repository at this point in the history
…rs (#111)
  • Loading branch information
antazoey authored Jul 26, 2024
1 parent 1d4fe1a commit 1a09913
Show file tree
Hide file tree
Showing 2 changed files with 17 additions and 2 deletions.
10 changes: 9 additions & 1 deletion ape_foundry/provider.py
Original file line number Diff line number Diff line change
Expand Up @@ -616,7 +616,15 @@ def get_virtual_machine_error(self, exception: Exception, **kwargs) -> VirtualMa
return VirtualMachineError(base_err=exception, **kwargs)

err_data = exception.args[0]
message = str(err_data.get("message")) if isinstance(err_data, dict) else err_data

if isinstance(err_data, dict):
message = str(err_data.get("message", f"{err_data}"))
elif isinstance(err_data, str):
message = err_data
elif msg := getattr(exception, "message", ""):
message = msg
else:
message = ""

if not message:
return VirtualMachineError(base_err=exception, **kwargs)
Expand Down
9 changes: 8 additions & 1 deletion tests/test_provider.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@
from ape.api import TraceAPI
from ape.api.accounts import ImpersonatedAccount
from ape.contracts import ContractContainer
from ape.exceptions import ContractLogicError, TransactionError
from ape.exceptions import ContractLogicError, TransactionError, VirtualMachineError
from ape_ethereum.trace import Trace
from ape_ethereum.transactions import TransactionStatusEnum, TransactionType
from eth_pydantic_types import HashBytes32
Expand Down Expand Up @@ -348,6 +348,13 @@ def test_get_virtual_machine_error_from_contract_logic_message_includes_base_err
assert actual.base_err == exception


def test_get_virtual_machine_error_first_arg_not_message(connected_provider):
# Handling weird edge case I have not seen in the wild but was raised in a GH issue.
exception = Exception(Exception())
actual = connected_provider.get_virtual_machine_error(exception)
assert isinstance(actual, VirtualMachineError)


def test_no_mining(project, local_network, connected_provider):
assert "--no-mining" not in connected_provider.build_command()
with project.temp_config(foundry={"auto_mine": "false"}):
Expand Down

0 comments on commit 1a09913

Please sign in to comment.