From 22d704d3e424f18436168070a8476efca15ab1f0 Mon Sep 17 00:00:00 2001 From: Matthias Seitz Date: Mon, 23 Dec 2024 11:54:07 +0100 Subject: [PATCH] chore: replace derive_more with thiserror (#1822) --- crates/rpc-types-eth/Cargo.toml | 2 +- crates/rpc-types-eth/src/block.rs | 16 +++------------- crates/rpc-types-eth/src/filter.rs | 6 ++---- crates/rpc-types-eth/src/transaction/error.rs | 11 ++--------- crates/rpc-types-eth/src/transaction/request.rs | 7 ++----- 5 files changed, 10 insertions(+), 32 deletions(-) diff --git a/crates/rpc-types-eth/Cargo.toml b/crates/rpc-types-eth/Cargo.toml index 10fb6bb8943..2ff33423346 100644 --- a/crates/rpc-types-eth/Cargo.toml +++ b/crates/rpc-types-eth/Cargo.toml @@ -27,7 +27,7 @@ alloy-rlp = { workspace = true, features = ["arrayvec", "derive"] } alloy-primitives = { workspace = true, features = ["rlp", "map"] } itertools.workspace = true -derive_more = { workspace = true, features = ["display"] } +thiserror.workspace = true # serde alloy-serde = { workspace = true, optional = true } diff --git a/crates/rpc-types-eth/src/block.rs b/crates/rpc-types-eth/src/block.rs index 00de11d5f95..4f02eda2f71 100644 --- a/crates/rpc-types-eth/src/block.rs +++ b/crates/rpc-types-eth/src/block.rs @@ -275,26 +275,16 @@ impl HeaderResponse for Header { } /// Error that can occur when converting other types to blocks -#[derive(Clone, Copy, Debug, derive_more::Display)] +#[derive(Clone, Copy, Debug, thiserror::Error)] pub enum BlockError { /// A transaction failed sender recovery - #[display("transaction failed sender recovery")] + #[error("transaction failed sender recovery")] InvalidSignature, /// A raw block failed to decode - #[display("failed to decode raw block {_0}")] + #[error("failed to decode raw block {0}")] RlpDecodeRawBlock(alloy_rlp::Error), } -#[cfg(feature = "std")] -impl std::error::Error for BlockError { - fn source(&self) -> Option<&(dyn std::error::Error + 'static)> { - match self { - Self::RlpDecodeRawBlock(err) => Some(err), - _ => None, - } - } -} - #[cfg(feature = "serde")] impl From for alloy_serde::WithOtherFields { fn from(inner: Block) -> Self { diff --git a/crates/rpc-types-eth/src/filter.rs b/crates/rpc-types-eth/src/filter.rs index a6dd6039479..3712509c5e7 100644 --- a/crates/rpc-types-eth/src/filter.rs +++ b/crates/rpc-types-eth/src/filter.rs @@ -153,10 +153,10 @@ impl From for Topic { } /// Represents errors that can occur when setting block filters in `FilterBlockOption`. -#[derive(Debug, PartialEq, Eq, derive_more::Display)] +#[derive(Debug, PartialEq, Eq, thiserror::Error)] pub enum FilterBlockError { /// Error indicating that the `from_block` is greater than the `to_block`. - #[display("`from_block` ({from}) is greater than `to_block` ({to})")] + #[error("`from_block` ({from}) is greater than `to_block` ({to})")] FromBlockGreaterThanToBlock { /// The starting block number, which is greater than `to`. from: u64, @@ -165,8 +165,6 @@ pub enum FilterBlockError { }, } -impl core::error::Error for FilterBlockError {} - /// Represents the target range of blocks for the filter #[derive(Clone, Copy, Debug, PartialEq, Eq, Hash)] pub enum FilterBlockOption { diff --git a/crates/rpc-types-eth/src/transaction/error.rs b/crates/rpc-types-eth/src/transaction/error.rs index 440afce683b..d77dbfb4cdb 100644 --- a/crates/rpc-types-eth/src/transaction/error.rs +++ b/crates/rpc-types-eth/src/transaction/error.rs @@ -2,16 +2,9 @@ use alloc::string::String; /// Error variants when converting from [crate::Transaction] to [alloy_consensus::Signed] /// transaction. -#[derive(Debug, derive_more::Display)] +#[derive(Debug, thiserror::Error)] pub enum ConversionError { /// A custom Conversion Error that doesn't fit other categories. - #[display("conversion error: {_0}")] + #[error("conversion error: {0}")] Custom(String), } - -#[cfg(feature = "std")] -impl std::error::Error for ConversionError { - fn source(&self) -> Option<&(dyn std::error::Error + 'static)> { - None - } -} diff --git a/crates/rpc-types-eth/src/transaction/request.rs b/crates/rpc-types-eth/src/transaction/request.rs index fde9b248000..2b914eb84aa 100644 --- a/crates/rpc-types-eth/src/transaction/request.rs +++ b/crates/rpc-types-eth/src/transaction/request.rs @@ -1099,15 +1099,12 @@ impl From> for TransactionInput { } /// Error thrown when both `data` and `input` fields are set and not equal. -#[derive(Debug, Default, derive_more::Display)] -#[display("both \"data\" and \"input\" are set and not equal. Please use \"input\" to pass transaction call data")] +#[derive(Debug, Default, thiserror::Error)] +#[error("both \"data\" and \"input\" are set and not equal. Please use \"input\" to pass transaction call data")] #[doc(alias = "TxInputError")] #[non_exhaustive] pub struct TransactionInputError; -#[cfg(feature = "std")] -impl std::error::Error for TransactionInputError {} - /// Error thrown when a transaction request cannot be built into a transaction. #[derive(Debug)] pub struct BuildTransactionErr {