From 87e76d1add75b6e30693f1abcad2f88d45577565 Mon Sep 17 00:00:00 2001 From: Juliya Smith Date: Fri, 1 Sep 2023 18:33:51 -0500 Subject: [PATCH] fix: bttr err handling --- ape_foundry/provider.py | 32 ++++++++++++++++++++++---------- 1 file changed, 22 insertions(+), 10 deletions(-) diff --git a/ape_foundry/provider.py b/ape_foundry/provider.py index 2120e47..d689e69 100644 --- a/ape_foundry/provider.py +++ b/ape_foundry/provider.py @@ -798,21 +798,33 @@ def _eth_call(self, arguments: List) -> bytes: txn_dict.pop("chainId", None) arguments[0] = txn_dict + trace = None try: result = self._make_request("eth_call", arguments) except Exception as err: - trace, trace2 = tee(self._create_trace_frame(x) for x in self._trace_call(arguments)[1]) - contract_address = arguments[0]["to"] - contract_type = self.chain_manager.contracts.get(contract_address) - method_id = arguments[0].get("data", "")[:10] or None - tb = ( - SourceTraceback.create(contract_type, trace, method_id) - if method_id and contract_type - else None - ) + contract_address = arguments[0].get("to") if len(arguments) > 0 else None + tb = None + if contract_address: + try: + trace, trace2 = tee( + self._create_trace_frame(x) for x in self._trace_call(arguments)[1] + ) + contract_type = self.chain_manager.contracts.get(contract_address) + method_id = arguments[0].get("data", "")[:10] or None + tb = ( + SourceTraceback.create(contract_type, trace2, method_id) + if method_id and contract_type + else None + ) + except Exception as sub_err: + logger.error(f"Error getting source traceback: {sub_err}") + + if trace is None: + trace = (self._create_trace_frame(x) for x in self._trace_call(arguments)[1]) + raise self.get_virtual_machine_error( - err, trace=trace2, contract_address=contract_address, source_traceback=tb + err, trace=trace, contract_address=contract_address, source_traceback=tb ) from err return HexBytes(result)