Skip to content

Commit

Permalink
chore: crates/consensus - Use derive_more::Error rather than impl std…
Browse files Browse the repository at this point in the history
…:error:Error (#10831)

Co-authored-by: garwah <garwah@garwah>
  • Loading branch information
garwahl and garwah authored Sep 11, 2024
1 parent 6764f7b commit cb7832e
Showing 1 changed file with 2 additions and 15 deletions.
17 changes: 2 additions & 15 deletions crates/consensus/consensus/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -127,7 +127,7 @@ pub trait Consensus: Debug + Send + Sync {
}

/// Consensus Errors
#[derive(Debug, PartialEq, Eq, Clone, derive_more::Display)]
#[derive(Debug, PartialEq, Eq, Clone, derive_more::Display, derive_more::Error)]
pub enum ConsensusError {
/// Error when the gas used in the header exceeds the gas limit.
#[display("block used gas ({gas_used}) is greater than gas limit ({gas_limit})")]
Expand Down Expand Up @@ -395,16 +395,6 @@ pub enum ConsensusError {
},
}

#[cfg(feature = "std")]
impl std::error::Error for ConsensusError {
fn source(&self) -> Option<&(dyn std::error::Error + 'static)> {
match self {
Self::InvalidTransaction(err) => std::error::Error::source(err),
_ => Option::None,
}
}
}

impl ConsensusError {
/// Returns `true` if the error is a state root error.
pub const fn is_state_root_error(&self) -> bool {
Expand All @@ -419,9 +409,6 @@ impl From<InvalidTransactionError> for ConsensusError {
}

/// `HeaderConsensusError` combines a `ConsensusError` with the `SealedHeader` it relates to.
#[derive(derive_more::Display, Debug)]
#[derive(derive_more::Display, derive_more::Error, Debug)]
#[display("Consensus error: {_0}, Invalid header: {_1:?}")]
pub struct HeaderConsensusError(ConsensusError, SealedHeader);

#[cfg(feature = "std")]
impl std::error::Error for HeaderConsensusError {}

0 comments on commit cb7832e

Please sign in to comment.