diff --git a/ape_safe/accounts.py b/ape_safe/accounts.py index 4281e31..d1f4077 100644 --- a/ape_safe/accounts.py +++ b/ape_safe/accounts.py @@ -14,8 +14,14 @@ from eth_utils import keccak, to_bytes, to_int from ethpm_types import ContractType -from .client import SafeClient, SafeTx -from .exceptions import NoLocalSigners, NotASigner, NotEnoughSignatures, handle_safe_logic_error +from ape_safe.client import SafeClient, SafeTx +from ape_safe.exceptions import ( + ClientUnavailable, + NoLocalSigners, + NotASigner, + NotEnoughSignatures, + handle_safe_logic_error, +) class AccountContainer(AccountContainerAPI): @@ -102,8 +108,9 @@ def fallback_handler(self) -> Optional[ContractInstance]: @cached_property def client(self) -> SafeClient: - if self.provider.chain_id not in self.account_file["deployed_chain_ids"]: - raise # Not valid on this chain + chain_id = self.provider.chain_id + if chain_id not in self.account_file["deployed_chain_ids"]: + raise ClientUnavailable(f"Safe client not valid on chain '{chain_id}'.") return SafeClient(address=self.address, chain_id=self.provider.chain_id) @@ -325,7 +332,7 @@ def sign_transaction( # Determine who is submitting the transaction (if enough signatures are gathered) if not submit and submitter: - raise # Cannot specify a submitter if not submitting + raise ValueError("Cannot specify a submitter if not submitting.") elif submit and not submitter: if len(self.local_signers) == 0: @@ -345,7 +352,7 @@ def sign_transaction( submitter = self.account_manager.load(submitter) elif not isinstance(submitter, AccountAPI): - raise # Cannot handle `submitter=type(submitter)` + raise TypeError(f"Cannot handle 'submitter={type(submitter)}'.") # Invariant: `submitter` should be either `AccountAPI` or we are not submitting here assert isinstance(submitter, AccountAPI) or not submit diff --git a/ape_safe/exceptions.py b/ape_safe/exceptions.py index 5455fff..9a9d982 100644 --- a/ape_safe/exceptions.py +++ b/ape_safe/exceptions.py @@ -1,5 +1,5 @@ from contextlib import ContextDecorator -from typing import Type +from typing import Optional, Type from ape.exceptions import ApeException, ContractLogicError, SignatureError from ape.types import AddressType @@ -27,6 +27,11 @@ def __init__(self, expected: int, actual: int): ) +class ClientUnavailable(ApeSafeException): + def __init__(self, message: Optional[str] = None) -> None: + super().__init__(message or "Client unavailable.") + + SAFE_ERROR_CODES = { "GS000": "Could not finish initialization", "GS001": "Threshold needs to be defined",