From ceb39e7f52925964039ff78c34b23d809450b872 Mon Sep 17 00:00:00 2001 From: Felix Henneke Date: Fri, 23 Aug 2024 11:30:12 +0200 Subject: [PATCH] Handle more exceptions in web3 (#116) 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. --- src/apis/web3api.py | 10 +++++++++- 1 file changed, 9 insertions(+), 1 deletion(-) diff --git a/src/apis/web3api.py b/src/apis/web3api.py index 4664cc6..961a27f 100644 --- a/src/apis/web3api.py +++ b/src/apis/web3api.py @@ -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] @@ -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]: @@ -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