diff --git a/multiversx_sdk_cli/base_transactions_controller.py b/multiversx_sdk_cli/base_transactions_controller.py index 60f685db..1a90c7f2 100644 --- a/multiversx_sdk_cli/base_transactions_controller.py +++ b/multiversx_sdk_cli/base_transactions_controller.py @@ -22,7 +22,7 @@ TRUE_STR_LOWER, ) from multiversx_sdk_cli.cosign_transaction import cosign_transaction -from multiversx_sdk_cli.errors import BadUserInput +from multiversx_sdk_cli.errors import BadUserInput, TransactionSigningError from multiversx_sdk_cli.guardian_relayer_data import GuardianRelayerData from multiversx_sdk_cli.interfaces import IAccount @@ -47,7 +47,10 @@ def sign_transaction( self._set_options_for_hash_signing_if_needed(transaction, sender, guardian, relayer) if sender: - transaction.signature = sender.sign_transaction(transaction) + try: + transaction.signature = sender.sign_transaction(transaction) + except Exception as e: + raise TransactionSigningError(f"Could not sign transaction: {str(e)}") self._sign_guarded_transaction_if_guardian( transaction, @@ -94,7 +97,10 @@ def _sign_guarded_transaction_if_guardian( ) -> Transaction: # If the guardian account is provided, we sign locally. Otherwise, we reach for the trusted cosign service. if guardian: - transaction.guardian_signature = guardian.sign_transaction(transaction) + try: + transaction.guardian_signature = guardian.sign_transaction(transaction) + except Exception as e: + raise TransactionSigningError(f"Could not sign transaction: {str(e)}") elif transaction.guardian and guardian_service_url and guardian_2fa_code: cosign_transaction(transaction, guardian_service_url, guardian_2fa_code) @@ -102,7 +108,10 @@ def _sign_guarded_transaction_if_guardian( def _sign_relayed_transaction_if_relayer(self, transaction: Transaction, relayer: Union[IAccount, None]): if relayer and transaction.relayer: - transaction.relayer_signature = relayer.sign_transaction(transaction) + try: + transaction.relayer_signature = relayer.sign_transaction(transaction) + except Exception as e: + raise TransactionSigningError(f"Could not sign transaction: {str(e)}") def _convert_args_to_typed_values(self, arguments: list[str]) -> list[Any]: args: list[Any] = [] diff --git a/multiversx_sdk_cli/cli_shared.py b/multiversx_sdk_cli/cli_shared.py index d833d6ff..283df25e 100644 --- a/multiversx_sdk_cli/cli_shared.py +++ b/multiversx_sdk_cli/cli_shared.py @@ -33,6 +33,7 @@ ArgumentsNotProvidedError, BadUsage, IncorrectWalletError, + LedgerError, ) from multiversx_sdk_cli.guardian_relayer_data import GuardianRelayerData from multiversx_sdk_cli.interfaces import IAccount @@ -346,7 +347,10 @@ def prepare_account(args: Any): hrp=hrp, ) elif args.ledger: - return LedgerAccount(address_index=args.sender_wallet_index) + try: + return LedgerAccount(address_index=args.sender_wallet_index) + except Exception as e: + raise LedgerError(str(e)) else: raise errors.NoWalletProvided() @@ -402,7 +406,10 @@ def load_guardian_account(args: Any) -> Union[IAccount, None]: hrp=hrp, ) elif args.guardian_ledger: - return LedgerAccount(address_index=args.guardian_wallet_index) + try: + return LedgerAccount(address_index=args.guardian_wallet_index) + except Exception as e: + raise LedgerError(str(e)) return None @@ -533,7 +540,10 @@ def load_relayer_account(args: Any) -> Union[IAccount, None]: hrp=hrp, ) elif args.relayer_ledger: - return LedgerAccount(address_index=args.relayer_wallet_index) + try: + return LedgerAccount(address_index=args.relayer_wallet_index) + except Exception as e: + raise LedgerError(str(e)) return None diff --git a/multiversx_sdk_cli/errors.py b/multiversx_sdk_cli/errors.py index 577d6207..1ec56977 100644 --- a/multiversx_sdk_cli/errors.py +++ b/multiversx_sdk_cli/errors.py @@ -149,3 +149,13 @@ def __init__(self, message: str): class InvalidArgumentsError(KnownError): def __init__(self, message: str): super().__init__(message) + + +class LedgerError(KnownError): + def __init__(self, message: str): + super().__init__(message) + + +class TransactionSigningError(KnownError): + def __init__(self, message: str): + super().__init__(message)