Skip to content

Commit

Permalink
chore: replace derive_more with thiserror (#1822)
Browse files Browse the repository at this point in the history
  • Loading branch information
mattsse authored Dec 23, 2024
1 parent 20f70c5 commit 22d704d
Show file tree
Hide file tree
Showing 5 changed files with 10 additions and 32 deletions.
2 changes: 1 addition & 1 deletion crates/rpc-types-eth/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -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 }
Expand Down
16 changes: 3 additions & 13 deletions crates/rpc-types-eth/src/block.rs
Original file line number Diff line number Diff line change
Expand Up @@ -275,26 +275,16 @@ impl<H: BlockHeader> HeaderResponse for Header<H> {
}

/// 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<Block> for alloy_serde::WithOtherFields<Block> {
fn from(inner: Block) -> Self {
Expand Down
6 changes: 2 additions & 4 deletions crates/rpc-types-eth/src/filter.rs
Original file line number Diff line number Diff line change
Expand Up @@ -153,10 +153,10 @@ impl From<U256> 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,
Expand All @@ -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 {
Expand Down
11 changes: 2 additions & 9 deletions crates/rpc-types-eth/src/transaction/error.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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
}
}
7 changes: 2 additions & 5 deletions crates/rpc-types-eth/src/transaction/request.rs
Original file line number Diff line number Diff line change
Expand Up @@ -1099,15 +1099,12 @@ impl From<Option<Bytes>> 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<T = TransactionRequest> {
Expand Down

0 comments on commit 22d704d

Please sign in to comment.