From b20bf8ebb004780b46a5e513a06818a4a6122f0f Mon Sep 17 00:00:00 2001 From: Jack May Date: Tue, 2 Mar 2021 11:13:41 -0800 Subject: [PATCH] improve cli insufficient funds error messages --- cli/src/checks.rs | 6 +++++- cli/src/cli.rs | 22 +++++++++++----------- cli/src/spend_utils.rs | 11 +++++++++-- 3 files changed, 25 insertions(+), 14 deletions(-) diff --git a/cli/src/checks.rs b/cli/src/checks.rs index 77abc74fe..3a3898ee8 100644 --- a/cli/src/checks.rs +++ b/cli/src/checks.rs @@ -86,9 +86,13 @@ pub fn check_account_for_spend_multiple_fees_with_commitment( return Err(CliError::InsufficientFundsForSpendAndFee( lamports_to_sol(balance), lamports_to_sol(fee), + *account_pubkey, )); } else { - return Err(CliError::InsufficientFundsForFee(lamports_to_sol(fee))); + return Err(CliError::InsufficientFundsForFee( + lamports_to_sol(fee), + *account_pubkey, + )); } } Ok(()) diff --git a/cli/src/cli.rs b/cli/src/cli.rs index 72a7926b4..599df37e6 100644 --- a/cli/src/cli.rs +++ b/cli/src/cli.rs @@ -369,25 +369,25 @@ pub struct CliCommandInfo { #[derive(Debug, Error)] pub enum CliError { - #[error("bad parameter: {0}")] + #[error("Bad parameter: {0}")] BadParameter(String), #[error(transparent)] ClientError(#[from] ClientError), - #[error("command not recognized: {0}")] + #[error("Command not recognized: {0}")] CommandNotRecognized(String), - #[error("insufficient funds for fee ({0} SOL)")] - InsufficientFundsForFee(f64), - #[error("insufficient funds for spend ({0} SOL)")] - InsufficientFundsForSpend(f64), - #[error("insufficient funds for spend ({0} SOL) and fee ({1} SOL)")] - InsufficientFundsForSpendAndFee(f64, f64), + #[error("Account {1} has insufficient funds for fee ({0} SOL)")] + InsufficientFundsForFee(f64, Pubkey), + #[error("Account {1} has insufficient funds for spend ({0} SOL)")] + InsufficientFundsForSpend(f64, Pubkey), + #[error("Account {2} has insufficient funds for spend ({0} SOL) + fee ({1} SOL)")] + InsufficientFundsForSpendAndFee(f64, f64, Pubkey), #[error(transparent)] InvalidNonce(nonce_utils::Error), - #[error("dynamic program error: {0}")] + #[error("Dynamic program error: {0}")] DynamicProgramError(String), - #[error("rpc request error: {0}")] + #[error("RPC request error: {0}")] RpcRequestError(String), - #[error("keypair file not found: {0}")] + #[error("Keypair file not found: {0}")] KeypairFileNotFound(String), } diff --git a/cli/src/spend_utils.rs b/cli/src/spend_utils.rs index a66e8a767..95431ccad 100644 --- a/cli/src/spend_utils.rs +++ b/cli/src/spend_utils.rs @@ -107,15 +107,22 @@ where return Err(CliError::InsufficientFundsForSpendAndFee( lamports_to_sol(spend), lamports_to_sol(fee), + *from_pubkey, )); } } else { if from_balance < spend { - return Err(CliError::InsufficientFundsForSpend(lamports_to_sol(spend))); + return Err(CliError::InsufficientFundsForSpend( + lamports_to_sol(spend), + *from_pubkey, + )); } if !check_account_for_balance_with_commitment(rpc_client, fee_pubkey, fee, commitment)? { - return Err(CliError::InsufficientFundsForFee(lamports_to_sol(fee))); + return Err(CliError::InsufficientFundsForFee( + lamports_to_sol(fee), + *fee_pubkey, + )); } } Ok((message, spend))