refactor: error display

This commit is contained in:
Halimao 2024-01-17 16:15:13 +08:00
parent ba6b9c4e41
commit a0e38b9f5e
2 changed files with 17 additions and 2 deletions

View File

@ -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),

View File

@ -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)?;