Skip to content

Commit 1b0383e

Browse files
committed
Open of unknown wallet should return proper error
Signed-off-by: Darko Kulic <[email protected]>
1 parent d0f11e2 commit 1b0383e

File tree

1 file changed

+14
-1
lines changed
  • libindy/src/services/wallet

1 file changed

+14
-1
lines changed

libindy/src/services/wallet/mod.rs

Lines changed: 14 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -265,7 +265,11 @@ impl WalletService {
265265

266266
let mut descriptor_json = String::new();
267267
let descriptor: WalletDescriptor = WalletDescriptor::from_json({
268-
let mut file = File::open(_wallet_descriptor_path(name))?; // FIXME: Better error!
268+
let wallet_descriptor_path = _wallet_descriptor_path(name);
269+
if !wallet_descriptor_path.exists() {
270+
return Err(WalletError::NotFound("Wallet descriptor path does not exist.".to_string()));
271+
}
272+
let mut file = File::open(_wallet_descriptor_path(name))?;
269273
file.read_to_string(&mut descriptor_json)?;
270274
descriptor_json.as_str()
271275
})?;
@@ -914,6 +918,15 @@ mod tests {
914918
wallet_service.open_wallet("test_wallet", None, &_credentials()).unwrap();
915919
}
916920

921+
#[test]
922+
fn wallet_service_open_unknown_wallet() {
923+
_cleanup();
924+
925+
let wallet_service = WalletService::new();
926+
let res = wallet_service.open_wallet("test_wallet_unknown", None, &_credentials());
927+
assert_match!(Err(WalletError::NotFound(_)), res);
928+
}
929+
917930
#[test]
918931
fn wallet_service_open_wallet_without_master_key_in_credentials_returns_error() {
919932
_cleanup();

0 commit comments

Comments
 (0)