diff --git a/crates/net/p2p/src/error.rs b/crates/net/p2p/src/error.rs index 285e83af2e6c..a52b9ccda97f 100644 --- a/crates/net/p2p/src/error.rs +++ b/crates/net/p2p/src/error.rs @@ -1,7 +1,7 @@ use std::ops::RangeInclusive; use super::headers::client::HeadersRequest; -use derive_more::Display; +use derive_more::{Display, Error}; use reth_consensus::ConsensusError; use reth_network_peers::WithPeerId; use reth_network_types::ReputationChangeKind; @@ -76,7 +76,7 @@ impl EthResponseValidator for RequestResult> { /// Error variants that can happen when sending requests to a session. /// /// Represents errors encountered when sending requests. -#[derive(Clone, Debug, Eq, PartialEq, Display)] +#[derive(Clone, Debug, Eq, PartialEq, Display, Error)] pub enum RequestError { /// Closed channel to the peer. #[display("closed channel to the peer")] @@ -126,14 +126,11 @@ impl From for RequestError { } } -#[cfg(feature = "std")] -impl std::error::Error for RequestError {} - /// The download result type pub type DownloadResult = Result; /// The downloader error type -#[derive(Debug, Clone, PartialEq, Eq, Display)] +#[derive(Debug, Clone, PartialEq, Eq, Display, Error)] pub enum DownloadError { /* ==================== HEADER ERRORS ==================== */ /// Header validation failed. @@ -144,6 +141,7 @@ pub enum DownloadError { /// Number of header failing validation number: u64, /// The details of validation failure + #[error(source)] error: Box, }, /// Received an invalid tip. @@ -216,20 +214,6 @@ impl From for DownloadError { } } -#[cfg(feature = "std")] -impl std::error::Error for DownloadError { - fn source(&self) -> Option<&(dyn std::error::Error + 'static)> { - match self { - Self::HeaderValidation { error, .. } | Self::BodyValidation { error, .. } => { - std::error::Error::source(error) - } - Self::RequestError(error) => std::error::Error::source(error), - Self::Provider(error) => std::error::Error::source(error), - _ => None, - } - } -} - #[cfg(test)] mod tests { use super::*; diff --git a/crates/net/p2p/src/headers/error.rs b/crates/net/p2p/src/headers/error.rs index 3112f9d7d456..b22aae9248ec 100644 --- a/crates/net/p2p/src/headers/error.rs +++ b/crates/net/p2p/src/headers/error.rs @@ -1,4 +1,4 @@ -use derive_more::Display; +use derive_more::{Display, Error}; use reth_consensus::ConsensusError; use reth_primitives::SealedHeader; @@ -6,7 +6,7 @@ use reth_primitives::SealedHeader; pub type HeadersDownloaderResult = Result; /// Error variants that can happen when sending requests to a session. -#[derive(Debug, Clone, Eq, PartialEq, Display)] +#[derive(Debug, Clone, Eq, PartialEq, Display, Error)] pub enum HeadersDownloaderError { /// The downloaded header cannot be attached to the local head, /// but is valid otherwise. @@ -17,15 +17,7 @@ pub enum HeadersDownloaderError { /// The header we attempted to attach. header: Box, /// The error that occurred when attempting to attach the header. + #[error(source)] error: Box, }, } - -#[cfg(feature = "std")] -impl std::error::Error for HeadersDownloaderError { - fn source(&self) -> Option<&(dyn std::error::Error + 'static)> { - match self { - Self::DetachedHead { error, .. } => Some(error), - } - } -} diff --git a/crates/primitives-traits/src/integer_list.rs b/crates/primitives-traits/src/integer_list.rs index df68d612aad6..3a4eb08903f9 100644 --- a/crates/primitives-traits/src/integer_list.rs +++ b/crates/primitives-traits/src/integer_list.rs @@ -140,7 +140,7 @@ impl<'a> Arbitrary<'a> for IntegerList { } /// Primitives error type. -#[derive(Debug, derive_more::Display)] +#[derive(Debug, derive_more::Display, derive_more::Error)] pub enum RoaringBitmapError { /// The provided input is invalid. #[display("the provided input is invalid")] @@ -150,9 +150,6 @@ pub enum RoaringBitmapError { FailedToDeserialize, } -#[cfg(feature = "std")] -impl std::error::Error for RoaringBitmapError {} - #[cfg(test)] mod tests { use super::*; diff --git a/crates/primitives/src/transaction/error.rs b/crates/primitives/src/transaction/error.rs index ed63f2f5ad6d..de4efa4d8f0b 100644 --- a/crates/primitives/src/transaction/error.rs +++ b/crates/primitives/src/transaction/error.rs @@ -66,7 +66,7 @@ impl std::error::Error for InvalidTransactionError {} /// Represents error variants that can happen when trying to convert a transaction to /// [`PooledTransactionsElement`](crate::PooledTransactionsElement) -#[derive(Debug, Clone, Eq, PartialEq, derive_more::Display)] +#[derive(Debug, Clone, Eq, PartialEq, derive_more::Display, derive_more::Error)] pub enum TransactionConversionError { /// This error variant is used when a transaction cannot be converted into a /// [`PooledTransactionsElement`](crate::PooledTransactionsElement) because it is not supported @@ -75,9 +75,6 @@ pub enum TransactionConversionError { UnsupportedForP2P, } -#[cfg(feature = "std")] -impl std::error::Error for TransactionConversionError {} - /// Represents error variants than can happen when trying to convert a /// [`TransactionSignedEcRecovered`](crate::TransactionSignedEcRecovered) transaction. #[derive(Debug, Clone, Eq, PartialEq, derive_more::Display)] diff --git a/crates/storage/errors/src/writer.rs b/crates/storage/errors/src/writer.rs index 71a1c47e2a18..10d4ad96ed3f 100644 --- a/crates/storage/errors/src/writer.rs +++ b/crates/storage/errors/src/writer.rs @@ -3,7 +3,7 @@ use reth_primitives::StaticFileSegment; /// `UnifiedStorageWriter` related errors /// `StorageWriter` related errors -#[derive(Clone, Debug, derive_more::Display, PartialEq, Eq)] +#[derive(Clone, Debug, derive_more::Display, PartialEq, Eq, derive_more::Error)] pub enum UnifiedStorageWriterError { /// Database writer is missing #[display("Database writer is missing")] @@ -18,16 +18,6 @@ pub enum UnifiedStorageWriterError { Database(DatabaseError), } -#[cfg(feature = "std")] -impl std::error::Error for UnifiedStorageWriterError { - fn source(&self) -> Option<&(dyn std::error::Error + 'static)> { - match self { - Self::Database(source) => std::error::Error::source(source), - _ => Option::None, - } - } -} - impl From for UnifiedStorageWriterError { fn from(error: DatabaseError) -> Self { Self::Database(error)