error: use derive-more Error for deriving error (#10841)

This commit is contained in:
Thomas Coratger
2024-09-17 12:01:29 +02:00
committed by GitHub
parent 30d8ec74ff
commit 1d0b18cd1a
5 changed files with 10 additions and 50 deletions

View File

@ -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<Vec<Header>> {
/// 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<oneshot::error::RecvError> for RequestError {
}
}
#[cfg(feature = "std")]
impl std::error::Error for RequestError {}
/// The download result type
pub type DownloadResult<T> = Result<T, DownloadError>;
/// 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<ConsensusError>,
},
/// Received an invalid tip.
@ -216,20 +214,6 @@ impl From<ProviderError> 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::*;

View File

@ -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<T> = Result<T, HeadersDownloaderError>;
/// 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<SealedHeader>,
/// The error that occurred when attempting to attach the header.
#[error(source)]
error: Box<ConsensusError>,
},
}
#[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),
}
}
}

View File

@ -138,7 +138,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")]
@ -148,9 +148,6 @@ pub enum RoaringBitmapError {
FailedToDeserialize,
}
#[cfg(feature = "std")]
impl std::error::Error for RoaringBitmapError {}
#[cfg(test)]
mod tests {
use super::*;

View File

@ -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)]

View File

@ -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<DatabaseError> for UnifiedStorageWriterError {
fn from(error: DatabaseError) -> Self {
Self::Database(error)