Skip to content

Commit

Permalink
Handle more exceptions in web3 (#116)
Browse files Browse the repository at this point in the history
This PR adds handling for general exceptions in some web3 functions.

There are crashes of the EBBO pod related to fetching data using web3py.
The proposed change would handle those errors more gracefully and also
show which errors are raised so they can be handled more explicitly.
  • Loading branch information
fhenneke authored Aug 23, 2024
1 parent ca023b1 commit ceb39e7
Showing 1 changed file with 9 additions and 1 deletion.
10 changes: 9 additions & 1 deletion src/apis/web3api.py
Original file line number Diff line number Diff line change
Expand Up @@ -45,6 +45,9 @@ def get_current_block_number(self) -> Optional[int]:
except ValueError as err:
self.logger.warning(f"Error while fetching block number: {err}")
return None
except Exception as err: # pylint: disable=W0718
self.logger.warning(f"Exception of type {type(err)} not handled: {err}")
return None

def get_filtered_receipts(
self, start_block: int, end_block: int, target: str, topics: list[Any]
Expand All @@ -65,6 +68,9 @@ def get_filtered_receipts(
except ValueError as err:
self.logger.warning(f"ValueError while fetching hashes: {err}")
return None
except Exception as err: # pylint: disable=W0718
self.logger.warning(f"Exception of type {type(err)} not handled: {err}")
return None
return log_receipts

def get_tx_hashes_by_block(self, start_block: int, end_block: int) -> list[str]:
Expand Down Expand Up @@ -111,7 +117,9 @@ def get_transaction(self, tx_hash: str) -> Optional[TxData]:
try:
transaction = self.web_3.eth.get_transaction(HexStr(tx_hash))
except Exception as err: # pylint: disable=W0718
self.logger.warning(f"Error while fetching transaction: {err}")
self.logger.warning(
f"Error of type {type(err)} while fetching transaction: {err}"
)
transaction = None
return transaction

Expand Down

0 comments on commit ceb39e7

Please sign in to comment.