Skip to content

Commit f5385d8

Browse files
authored
Merge pull request hyperledger-indy#857 from Artemkaaas/bugfix/IS-721
Corrected error handling in CLI
2 parents b8ad861 + aa94df5 commit f5385d8

File tree

2 files changed

+35
-4
lines changed

2 files changed

+35
-4
lines changed

cli/src/commands/pool.rs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -89,6 +89,7 @@ pub mod connect_command {
8989
}
9090
Err(ErrorCode::PoolLedgerNotCreatedError) => Err(println_err!("Pool \"{}\" does not exist.", name)),
9191
Err(ErrorCode::CommonIOError) => Err(println_err!("Pool \"{}\" does not exist.", name)),
92+
Err(ErrorCode::PoolLedgerNotCreatedError) => Err(println_err!("Pool \"{}\" does not exist.", name)),
9293
Err(ErrorCode::PoolLedgerTerminated) => Err(println_err!("Pool \"{}\" does not exist.", name)),
9394
Err(ErrorCode::PoolLedgerTimeout) => Err(println_err!("Pool \"{}\" has not been connected.", name)),
9495
Err(err) => Err(println_err!("Indy SDK error occurred {:?}", err)),

cli/src/commands/wallet.rs

Lines changed: 34 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -110,9 +110,8 @@ pub mod open_command {
110110
match err {
111111
ErrorCode::CommonInvalidStructure => Err(println_err!("Invalid wallet config")),
112112
ErrorCode::WalletAlreadyOpenedError => Err(println_err!("Wallet \"{}\" already opened", name)),
113-
ErrorCode::WalletAccessFailed => Err(println_err!("Cannot open encrypted wallet \"{}\"", name)),
113+
ErrorCode::WalletAccessFailed => Err(println_err!("Cannot open wallet \"{}\". Invalid key \"{}\" has been provided", name, key)),
114114
ErrorCode::WalletNotFoundError => Err(println_err!("Wallet \"{}\" not found or unavailable", name)),
115-
ErrorCode::CommonIOError => Err(println_err!("Wallet \"{}\" not found or unavailable", name)),
116115
err => Err(println_err!("Indy SDK error occurred {:?}", err)),
117116
}
118117
}
@@ -238,8 +237,8 @@ pub mod delete_command {
238237
let res = match Wallet::delete_wallet(name, credentials.as_str()) {
239238
Ok(()) => Ok(println_succ!("Wallet \"{}\" has been deleted", name)),
240239
Err(ErrorCode::CommonIOError) => Err(println_err!("Wallet \"{}\" not found or unavailable", name)),
241-
Err(ErrorCode::WalletInputError) => Err(println_err!("Invalid wallet key \"{}\"", key)),
242-
Err(ErrorCode::WalletDecodingError) => Err(println_err!("Invalid wallet key \"{}\"", key)),
240+
Err(ErrorCode::WalletNotFoundError) => Err(println_err!("Wallet \"{}\" not found or unavailable", name)),
241+
Err(ErrorCode::WalletAccessFailed) => Err(println_err!("Cannot delete wallet \"{}\". Invalid key \"{}\" has been provided ", name, key)),
243242
Err(err) => Err(println_err!("Indy SDK error occurred {:?}", err)),
244243
};
245244

@@ -394,6 +393,21 @@ pub mod tests {
394393
}
395394
delete_wallet(&ctx);
396395
}
396+
397+
#[test]
398+
pub fn open_works_for_wrong_key() {
399+
let ctx = CommandContext::new();
400+
401+
create_wallet(&ctx);
402+
{
403+
let cmd = open_command::new();
404+
let mut params = CommandParams::new();
405+
params.insert("name", WALLET.to_string());
406+
params.insert("key", "other_key".to_string());
407+
cmd.execute(&ctx, &params).unwrap_err();
408+
}
409+
delete_wallet(&ctx);
410+
}
397411
}
398412

399413
mod list {
@@ -532,6 +546,22 @@ pub mod tests {
532546
close_and_delete_wallet(&ctx);
533547
TestUtils::cleanup_storage();
534548
}
549+
550+
#[test]
551+
pub fn delete_works_for_wrong_key() {
552+
TestUtils::cleanup_storage();
553+
let ctx = CommandContext::new();
554+
555+
create_wallet(&ctx);
556+
{
557+
let cmd = delete_command::new();
558+
let mut params = CommandParams::new();
559+
params.insert("name", WALLET.to_string());
560+
params.insert("key", "other_key".to_string());
561+
cmd.execute(&ctx, &params).unwrap_err();
562+
}
563+
TestUtils::cleanup_storage();
564+
}
535565
}
536566

537567
pub fn create_wallet(ctx: &CommandContext) {

0 commit comments

Comments
 (0)