From df22c2eb8cd4fdf51dba52d7e1b9fb53de896d3f Mon Sep 17 00:00:00 2001 From: Kevin Heavey Date: Fri, 11 Oct 2024 21:48:13 +0400 Subject: [PATCH] remove thiserror from solana-derivation-path (#3086) * remove thiserror from solana-derivation-path * fix excessively qualified path --- Cargo.lock | 1 - programs/sbf/Cargo.lock | 1 - sdk/derivation-path/Cargo.toml | 1 - sdk/derivation-path/src/lib.rs | 29 +++++++++++++++++++++++------ 4 files changed, 23 insertions(+), 9 deletions(-) diff --git a/Cargo.lock b/Cargo.lock index 78438b2e9ea6a3..d293a5e68877f8 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -6522,7 +6522,6 @@ dependencies = [ "assert_matches", "derivation-path", "qstring", - "thiserror", "uriparse", ] diff --git a/programs/sbf/Cargo.lock b/programs/sbf/Cargo.lock index 6900b5ac87e17d..11f3c749413333 100644 --- a/programs/sbf/Cargo.lock +++ b/programs/sbf/Cargo.lock @@ -5213,7 +5213,6 @@ version = "2.1.0" dependencies = [ "derivation-path", "qstring", - "thiserror", "uriparse", ] diff --git a/sdk/derivation-path/Cargo.toml b/sdk/derivation-path/Cargo.toml index 8b82b091a07861..ada1f3c42daadc 100644 --- a/sdk/derivation-path/Cargo.toml +++ b/sdk/derivation-path/Cargo.toml @@ -12,7 +12,6 @@ edition = { workspace = true } [dependencies] derivation-path = { workspace = true } qstring = { workspace = true } -thiserror = { workspace = true } uriparse = { workspace = true } [dev-dependencies] diff --git a/sdk/derivation-path/src/lib.rs b/sdk/derivation-path/src/lib.rs index 4e76ddf95d2a9b..f3deea068d0292 100644 --- a/sdk/derivation-path/src/lib.rs +++ b/sdk/derivation-path/src/lib.rs @@ -17,7 +17,6 @@ use { fmt, str::FromStr, }, - thiserror::Error, uriparse::URIReference, }; @@ -25,14 +24,25 @@ const ACCOUNT_INDEX: usize = 2; const CHANGE_INDEX: usize = 3; /// Derivation path error. -#[derive(Error, Debug, Clone, PartialEq, Eq)] +#[derive(Debug, Clone, PartialEq, Eq)] pub enum DerivationPathError { - #[error("invalid derivation path: {0}")] InvalidDerivationPath(String), - #[error("infallible")] Infallible, } +impl std::error::Error for DerivationPathError {} + +impl fmt::Display for DerivationPathError { + fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result { + match self { + DerivationPathError::InvalidDerivationPath(p) => { + write!(f, "invalid derivation path: {p}",) + } + DerivationPathError::Infallible => f.write_str("infallible"), + } + } +} + impl From for DerivationPathError { fn from(_: Infallible) -> Self { Self::Infallible @@ -211,10 +221,17 @@ impl<'a> IntoIterator for &'a DerivationPath { const QUERY_KEY_FULL_PATH: &str = "full-path"; const QUERY_KEY_KEY: &str = "key"; -#[derive(Clone, Debug, Error, PartialEq, Eq)] -#[error("invalid query key `{0}`")] +#[derive(Clone, Debug, PartialEq, Eq)] struct QueryKeyError(String); +impl std::error::Error for QueryKeyError {} + +impl fmt::Display for QueryKeyError { + fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result { + write!(f, "invalid query key `{}`", self.0) + } +} + enum QueryKey { FullPath, Key,