Migrate custom error trait impls to thiserror (#1856)

* Migrate to thiserror

* missing bits

* review comment

* Apply suggestions from code review

Co-authored-by: Niklas Adolfsson <niklasadolfsson1@gmail.com>

* From<scale_decode::visitor::Error> to remove Into::intos

* scale crates for core::error::Error

* bump msrv 1.81

* make signer crate compile

---------

Co-authored-by: Niklas Adolfsson <niklasadolfsson1@gmail.com>
Co-authored-by: James Wilson <james.wilson@parity.io>
This commit is contained in:
Pavlo Khrystenko
2024-11-18 10:39:14 +01:00
committed by GitHub
parent 137701757e
commit 7d1002192e
17 changed files with 329 additions and 477 deletions
+5 -17
View File
@@ -6,11 +6,12 @@
use crate::ecdsa;
use alloc::format;
use core::fmt::{Display, Formatter};
use core::str::FromStr;
use keccak_hash::keccak;
use secp256k1::Message;
use thiserror::Error as DeriveError;
const SECRET_KEY_LENGTH: usize = 32;
/// Bytes representing a private key.
@@ -201,29 +202,16 @@ pub fn verify<M: AsRef<[u8]>>(sig: &Signature, message: M, pubkey: &PublicKey) -
}
/// An error handed back if creating a keypair fails.
#[derive(Debug, PartialEq)]
#[derive(Debug, PartialEq, DeriveError)]
pub enum Error {
/// Invalid seed.
#[error("Invalid seed (was it the wrong length?)")]
InvalidSeed,
/// Invalid derivation path.
#[error("Could not derive from path; some values in the path may have been >= 2^31?")]
DeriveFromPath,
}
impl Display for Error {
fn fmt(&self, f: &mut Formatter<'_>) -> core::fmt::Result {
match self {
Error::InvalidSeed => write!(f, "Invalid seed (was it the wrong length?)"),
Error::DeriveFromPath => write!(
f,
"Could not derive from path; some values in the path may have been >= 2^31?"
),
}
}
}
#[cfg(feature = "std")]
impl std::error::Error for Error {}
/// Dev accounts, helpful for testing but not to be used in production,
/// since the secret keys are known.
pub mod dev {