diff --git a/src/ape/api/providers.py b/src/ape/api/providers.py index 3a483f245d..ec6fd42df5 100644 --- a/src/ape/api/providers.py +++ b/src/ape/api/providers.py @@ -886,7 +886,7 @@ def get_block(self, block_id: BlockID) -> BlockAPI: try: block_data = dict(self.web3.eth.get_block(block_id)) except Exception as err: - raise BlockNotFoundError(block_id) from err + raise BlockNotFoundError(block_id, reason=str(err)) from err # Some nodes (like anvil) will not have a base fee if set to 0. if "baseFeePerGas" in block_data and block_data.get("baseFeePerGas") is None: diff --git a/src/ape/exceptions.py b/src/ape/exceptions.py index dbb7bb450d..a900118882 100644 --- a/src/ape/exceptions.py +++ b/src/ape/exceptions.py @@ -428,13 +428,21 @@ class BlockNotFoundError(ProviderError): Raised when unable to find a block. """ - def __init__(self, block_id: "BlockID"): + def __init__(self, block_id: "BlockID", reason: Optional[str] = None): if isinstance(block_id, bytes): block_id_str = block_id.hex() else: block_id_str = str(block_id) - super().__init__(f"Block with ID '{block_id_str}' not found.") + message = ( + "Missing latest block." + if block_id == "latest" + else f"Block with ID '{block_id_str}' not found." + ) + if reason: + message = f"{message} Reason: {reason}" + + super().__init__(message) class TransactionNotFoundError(ProviderError):