Skip to content
This repository has been archived by the owner on Nov 15, 2023. It is now read-only.

Commit

Permalink
sc-keystore: Improve weird error message (#10584)
Browse files Browse the repository at this point in the history
The keystore would print "Invalid password" when a key was stored using an incorrect public key.
This pr improves the error message to communicate better to the user on what is wrong.
  • Loading branch information
bkchr authored Jan 5, 2022
1 parent 823581c commit 2ae6242
Show file tree
Hide file tree
Showing 2 changed files with 7 additions and 4 deletions.
9 changes: 6 additions & 3 deletions client/keystore/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -35,8 +35,11 @@ pub enum Error {
/// JSON error.
Json(serde_json::Error),
/// Invalid password.
#[display(fmt = "Invalid password")]
InvalidPassword,
#[display(
fmt = "Requested public key and public key of the loaded private key do not match. \n
This means either that the keystore password is incorrect or that the private key was stored under a wrong public key."
)]
PublicKeyMismatch,
/// Invalid BIP39 phrase
#[display(fmt = "Invalid recovery phrase (BIP39) data")]
InvalidPhrase,
Expand All @@ -58,7 +61,7 @@ impl From<Error> for TraitError {
fn from(error: Error) -> Self {
match error {
Error::KeyNotSupported(id) => TraitError::KeyNotSupported(id),
Error::InvalidSeed | Error::InvalidPhrase | Error::InvalidPassword =>
Error::InvalidSeed | Error::InvalidPhrase | Error::PublicKeyMismatch =>
TraitError::ValidationError(error.to_string()),
Error::Unavailable => TraitError::Unavailable,
Error::Io(e) => TraitError::Other(e.to_string()),
Expand Down
2 changes: 1 addition & 1 deletion client/keystore/src/local.rs
Original file line number Diff line number Diff line change
Expand Up @@ -503,7 +503,7 @@ impl KeystoreInner {
if &pair.public() == public {
Ok(Some(pair))
} else {
Err(Error::InvalidPassword)
Err(Error::PublicKeyMismatch)
}
}

Expand Down

0 comments on commit 2ae6242

Please sign in to comment.