diff --git a/errors/src/errors/cli/cli_errors.rs b/errors/src/errors/cli/cli_errors.rs index 27d885ebc7..f1c23ab558 100644 --- a/errors/src/errors/cli/cli_errors.rs +++ b/errors/src/errors/cli/cli_errors.rs @@ -179,6 +179,13 @@ create_messages!( help: None, } + @backtraced + failed_to_parse_private_key { + args: (error: impl Display), + msg: format!("Failed to parse private key.\nSnarkVM Error: {error}"), + help: None, + } + @backtraced failed_to_execute_account { args: (error: impl Display), diff --git a/leo/cli/commands/account.rs b/leo/cli/commands/account.rs index d31f092d6e..103aeabff4 100644 --- a/leo/cli/commands/account.rs +++ b/leo/cli/commands/account.rs @@ -89,9 +89,17 @@ impl Command for Account { let priv_key = match discreet { true => { let private_key_input = rpassword::prompt_password("Please enter your private key: ").unwrap(); - FromStr::from_str(&private_key_input).map_err(CliError::failed_to_execute_account)? + FromStr::from_str(&private_key_input).map_err(CliError::failed_to_parse_private_key)? } - false => private_key.expect("PRIVATE_KEY shouldn't be empty when --discreet is false"), + false => match private_key { + Some(private_key) => private_key, + None => { + return Err(CliError::failed_to_execute_account( + "PRIVATE_KEY shouldn't be empty when --discreet is false", + ) + .into()) + } + }, }; // Derive the view key and address and print to stdout. print_keys(priv_key, discreet)?;