Skip to content

Commit

Permalink
Improve error logging for individual calls
Browse files Browse the repository at this point in the history
  • Loading branch information
gnpar committed Sep 19, 2024
1 parent 7f64fde commit 77e0629
Showing 1 changed file with 7 additions and 3 deletions.
10 changes: 7 additions & 3 deletions src/eth_exporter/chaindata.py
Original file line number Diff line number Diff line change
Expand Up @@ -175,15 +175,19 @@ def bind(self, metric: CallMetricDefinition):
self.metrics.append(metric)

async def __call__(self, w3, block, sem: asyncio.Semaphore) -> List[CallResult]:
async def execute_call(func):
async def execute_call(address, func):
async with sem:
return await func.call(block_identifier=block.number)
try:
return await func.call(block_identifier=block.number)
except Exception as e:
logger.error("Error calling %s.%s: %s", address.name, func, e)
raise

calls = []
for address in self.addresses:
contract = w3.eth.contract(address=address.address, abi=self.abi, decode_tuples=True)
function = contract.functions[self.function](*[arg.value for arg in self.arguments])
calls.append(execute_call(function))
calls.append(execute_call(address, function))

results = []
for address, result in zip(self.addresses, await asyncio.gather(*calls)):
Expand Down

0 comments on commit 77e0629

Please sign in to comment.