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
+4 -14
View File
@@ -2,13 +2,13 @@
// This file is dual-licensed as Apache-2.0 or GPL-3.0.
// see LICENSE for license details.
use core::fmt::Display;
use super::DeriveJunction;
use alloc::{string::ToString, vec::Vec};
use regex::Regex;
use secrecy::SecretString;
use thiserror::Error as DeriveError;
// This code is taken from sp_core::crypto::DeriveJunction. The logic should be identical,
// though the code is tweaked a touch!
@@ -116,23 +116,13 @@ impl core::str::FromStr for SecretUri {
}
/// This is returned if `FromStr` cannot parse a string into a `SecretUri`.
#[derive(Debug, Copy, Clone, PartialEq)]
#[derive(Debug, Copy, Clone, PartialEq, DeriveError)]
pub enum SecretUriError {
/// Parsing the secret URI from a string failed; wrong format.
#[error("Invalid secret phrase format")]
InvalidFormat,
}
impl Display for SecretUriError {
fn fmt(&self, f: &mut core::fmt::Formatter<'_>) -> core::fmt::Result {
match self {
SecretUriError::InvalidFormat => write!(f, "Invalid secret phrase format"),
}
}
}
#[cfg(feature = "std")]
impl std::error::Error for SecretUriError {}
once_static_cloned! {
/// Interpret a phrase like:
///