Skip to content

Commit d48fdfc

Browse files
committed
Node/p2p: add filename when failed to decrypt a file
1 parent 14e8a03 commit d48fdfc

File tree

3 files changed

+9
-5
lines changed

3 files changed

+9
-5
lines changed

node/account/src/secret_key.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -237,7 +237,7 @@ mod tests {
237237

238238
// load and decrypt
239239
let decrypted = AccountSecretKey::from_encrypted_file(&tmp_path, password)
240-
.expect("Failed to decrypt secret key file");
240+
.unwrap_or_else(|_| panic!("Failed to decrypt secret key file: {}", tmp_path));
241241

242242
assert_eq!(
243243
new_key.public_key(),
@@ -252,7 +252,7 @@ mod tests {
252252
let key_path = "../tests/files/accounts/test-key-1";
253253
let expected_public_key = "B62qmg7n4XqU3SFwx9KD9B7gxsKwxJP5GmxtBpHp1uxyN3grujii9a1";
254254
let decrypted = AccountSecretKey::from_encrypted_file(key_path, password)
255-
.expect("Failed to decrypt secret key file");
255+
.unwrap_or_else(|_| panic!("Failed to decrypt secret key file: {}", key_path));
256256

257257
assert_eq!(
258258
expected_public_key.to_string(),

node/native/src/node/builder.rs

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -213,8 +213,12 @@ impl NodeBuilder {
213213
password: &str,
214214
provers: Option<BlockProver>,
215215
) -> anyhow::Result<&mut Self> {
216-
let key = AccountSecretKey::from_encrypted_file(path, password)
217-
.context("Failed to decrypt secret key file")?;
216+
let key = AccountSecretKey::from_encrypted_file(&path, password).with_context(|| {
217+
format!(
218+
"Failed to decrypt secret key file: {}",
219+
path.as_ref().display()
220+
)
221+
})?;
218222
Ok(self.block_producer(key, provers))
219223
}
220224

p2p/src/identity/secret_key.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -295,7 +295,7 @@ mod tests {
295295
let expected_peer_id = "12D3KooWDxyuJKSsVEwNR13UVwf4PEfs4yHkk3ecZipBPv3Y3Sac";
296296

297297
let decrypted = SecretKey::from_encrypted_file(key_path, password)
298-
.expect("Failed to decrypt secret key file");
298+
.unwrap_or_else(|_| panic!("Failed to decrypt secret key file: {}", key_path));
299299

300300
let peer_id = decrypted.public_key().peer_id().to_libp2p_string();
301301
assert_eq!(expected_peer_id, peer_id);

0 commit comments

Comments
 (0)