mirror of
https://github.com/hl-archive-node/nanoreth.git
synced 2025-12-06 10:59:55 +00:00
chore(reth-execution-errors): use derive_more::From when possible (#10897)
This commit is contained in:
@ -14,7 +14,7 @@ extern crate alloc;
|
|||||||
use alloc::{boxed::Box, string::String};
|
use alloc::{boxed::Box, string::String};
|
||||||
use alloy_eips::BlockNumHash;
|
use alloy_eips::BlockNumHash;
|
||||||
use alloy_primitives::B256;
|
use alloy_primitives::B256;
|
||||||
use derive_more::Display;
|
use derive_more::{Display, From};
|
||||||
use reth_consensus::ConsensusError;
|
use reth_consensus::ConsensusError;
|
||||||
use reth_prune_types::PruneSegmentError;
|
use reth_prune_types::PruneSegmentError;
|
||||||
use reth_storage_errors::provider::ProviderError;
|
use reth_storage_errors::provider::ProviderError;
|
||||||
@ -137,7 +137,7 @@ impl std::error::Error for BlockValidationError {
|
|||||||
}
|
}
|
||||||
|
|
||||||
/// `BlockExecutor` Errors
|
/// `BlockExecutor` Errors
|
||||||
#[derive(Debug, Display)]
|
#[derive(Debug, From, Display)]
|
||||||
pub enum BlockExecutionError {
|
pub enum BlockExecutionError {
|
||||||
/// Validation error, transparently wrapping [`BlockValidationError`]
|
/// Validation error, transparently wrapping [`BlockValidationError`]
|
||||||
Validation(BlockValidationError),
|
Validation(BlockValidationError),
|
||||||
@ -179,24 +179,6 @@ impl BlockExecutionError {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
impl From<BlockValidationError> for BlockExecutionError {
|
|
||||||
fn from(error: BlockValidationError) -> Self {
|
|
||||||
Self::Validation(error)
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
impl From<ConsensusError> for BlockExecutionError {
|
|
||||||
fn from(error: ConsensusError) -> Self {
|
|
||||||
Self::Consensus(error)
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
impl From<InternalBlockExecutionError> for BlockExecutionError {
|
|
||||||
fn from(error: InternalBlockExecutionError) -> Self {
|
|
||||||
Self::Internal(error)
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
impl From<ProviderError> for BlockExecutionError {
|
impl From<ProviderError> for BlockExecutionError {
|
||||||
fn from(error: ProviderError) -> Self {
|
fn from(error: ProviderError) -> Self {
|
||||||
InternalBlockExecutionError::from(error).into()
|
InternalBlockExecutionError::from(error).into()
|
||||||
@ -215,9 +197,10 @@ impl std::error::Error for BlockExecutionError {
|
|||||||
}
|
}
|
||||||
|
|
||||||
/// Internal (i.e., not validation or consensus related) `BlockExecutor` Errors
|
/// Internal (i.e., not validation or consensus related) `BlockExecutor` Errors
|
||||||
#[derive(Display, Debug)]
|
#[derive(Display, Debug, From)]
|
||||||
pub enum InternalBlockExecutionError {
|
pub enum InternalBlockExecutionError {
|
||||||
/// Pruning error, transparently wrapping [`PruneSegmentError`]
|
/// Pruning error, transparently wrapping [`PruneSegmentError`]
|
||||||
|
#[from]
|
||||||
Pruning(PruneSegmentError),
|
Pruning(PruneSegmentError),
|
||||||
/// Error when appending chain on fork is not possible
|
/// Error when appending chain on fork is not possible
|
||||||
#[display(
|
#[display(
|
||||||
@ -230,6 +213,7 @@ pub enum InternalBlockExecutionError {
|
|||||||
other_chain_fork: Box<BlockNumHash>,
|
other_chain_fork: Box<BlockNumHash>,
|
||||||
},
|
},
|
||||||
/// Error when fetching latest block state.
|
/// Error when fetching latest block state.
|
||||||
|
#[from]
|
||||||
LatestBlock(ProviderError),
|
LatestBlock(ProviderError),
|
||||||
/// Arbitrary Block Executor Errors
|
/// Arbitrary Block Executor Errors
|
||||||
#[cfg(feature = "std")]
|
#[cfg(feature = "std")]
|
||||||
@ -253,18 +237,6 @@ impl InternalBlockExecutionError {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
impl From<PruneSegmentError> for InternalBlockExecutionError {
|
|
||||||
fn from(error: PruneSegmentError) -> Self {
|
|
||||||
Self::Pruning(error)
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
impl From<ProviderError> for InternalBlockExecutionError {
|
|
||||||
fn from(error: ProviderError) -> Self {
|
|
||||||
Self::LatestBlock(error)
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
#[cfg(feature = "std")]
|
#[cfg(feature = "std")]
|
||||||
impl std::error::Error for InternalBlockExecutionError {
|
impl std::error::Error for InternalBlockExecutionError {
|
||||||
fn source(&self) -> Option<&(dyn std::error::Error + 'static)> {
|
fn source(&self) -> Option<&(dyn std::error::Error + 'static)> {
|
||||||
|
|||||||
@ -2,12 +2,12 @@
|
|||||||
|
|
||||||
use alloc::string::ToString;
|
use alloc::string::ToString;
|
||||||
use alloy_primitives::B256;
|
use alloy_primitives::B256;
|
||||||
use derive_more::Display;
|
use derive_more::{Display, From};
|
||||||
use nybbles::Nibbles;
|
use nybbles::Nibbles;
|
||||||
use reth_storage_errors::{db::DatabaseError, provider::ProviderError};
|
use reth_storage_errors::{db::DatabaseError, provider::ProviderError};
|
||||||
|
|
||||||
/// State root errors.
|
/// State root errors.
|
||||||
#[derive(Display, Debug, PartialEq, Eq, Clone)]
|
#[derive(Display, Debug, From, PartialEq, Eq, Clone)]
|
||||||
pub enum StateRootError {
|
pub enum StateRootError {
|
||||||
/// Internal database error.
|
/// Internal database error.
|
||||||
Database(DatabaseError),
|
Database(DatabaseError),
|
||||||
@ -15,18 +15,6 @@ pub enum StateRootError {
|
|||||||
StorageRootError(StorageRootError),
|
StorageRootError(StorageRootError),
|
||||||
}
|
}
|
||||||
|
|
||||||
impl From<DatabaseError> for StateRootError {
|
|
||||||
fn from(error: DatabaseError) -> Self {
|
|
||||||
Self::Database(error)
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
impl From<StorageRootError> for StateRootError {
|
|
||||||
fn from(error: StorageRootError) -> Self {
|
|
||||||
Self::StorageRootError(error)
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
#[cfg(feature = "std")]
|
#[cfg(feature = "std")]
|
||||||
impl std::error::Error for StateRootError {
|
impl std::error::Error for StateRootError {
|
||||||
fn source(&self) -> Option<&(dyn std::error::Error + 'static)> {
|
fn source(&self) -> Option<&(dyn std::error::Error + 'static)> {
|
||||||
@ -47,18 +35,12 @@ impl From<StateRootError> for DatabaseError {
|
|||||||
}
|
}
|
||||||
|
|
||||||
/// Storage root error.
|
/// Storage root error.
|
||||||
#[derive(Display, PartialEq, Eq, Clone, Debug)]
|
#[derive(Display, From, PartialEq, Eq, Clone, Debug)]
|
||||||
pub enum StorageRootError {
|
pub enum StorageRootError {
|
||||||
/// Internal database error.
|
/// Internal database error.
|
||||||
Database(DatabaseError),
|
Database(DatabaseError),
|
||||||
}
|
}
|
||||||
|
|
||||||
impl From<DatabaseError> for StorageRootError {
|
|
||||||
fn from(error: DatabaseError) -> Self {
|
|
||||||
Self::Database(error)
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
impl From<StorageRootError> for DatabaseError {
|
impl From<StorageRootError> for DatabaseError {
|
||||||
fn from(err: StorageRootError) -> Self {
|
fn from(err: StorageRootError) -> Self {
|
||||||
match err {
|
match err {
|
||||||
@ -77,7 +59,7 @@ impl std::error::Error for StorageRootError {
|
|||||||
}
|
}
|
||||||
|
|
||||||
/// State proof errors.
|
/// State proof errors.
|
||||||
#[derive(Display, Debug, PartialEq, Eq, Clone)]
|
#[derive(Display, From, Debug, PartialEq, Eq, Clone)]
|
||||||
pub enum StateProofError {
|
pub enum StateProofError {
|
||||||
/// Internal database error.
|
/// Internal database error.
|
||||||
Database(DatabaseError),
|
Database(DatabaseError),
|
||||||
@ -85,18 +67,6 @@ pub enum StateProofError {
|
|||||||
Rlp(alloy_rlp::Error),
|
Rlp(alloy_rlp::Error),
|
||||||
}
|
}
|
||||||
|
|
||||||
impl From<DatabaseError> for StateProofError {
|
|
||||||
fn from(error: DatabaseError) -> Self {
|
|
||||||
Self::Database(error)
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
impl From<alloy_rlp::Error> for StateProofError {
|
|
||||||
fn from(error: alloy_rlp::Error) -> Self {
|
|
||||||
Self::Rlp(error)
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
impl From<StateProofError> for ProviderError {
|
impl From<StateProofError> for ProviderError {
|
||||||
fn from(value: StateProofError) -> Self {
|
fn from(value: StateProofError) -> Self {
|
||||||
match value {
|
match value {
|
||||||
@ -117,11 +87,13 @@ impl std::error::Error for StateProofError {
|
|||||||
}
|
}
|
||||||
|
|
||||||
/// Trie witness errors.
|
/// Trie witness errors.
|
||||||
#[derive(Display, Debug, PartialEq, Eq, Clone)]
|
#[derive(Display, From, Debug, PartialEq, Eq, Clone)]
|
||||||
pub enum TrieWitnessError {
|
pub enum TrieWitnessError {
|
||||||
/// Error gather proofs.
|
/// Error gather proofs.
|
||||||
|
#[from]
|
||||||
Proof(StateProofError),
|
Proof(StateProofError),
|
||||||
/// RLP decoding error.
|
/// RLP decoding error.
|
||||||
|
#[from]
|
||||||
Rlp(alloy_rlp::Error),
|
Rlp(alloy_rlp::Error),
|
||||||
/// Missing account.
|
/// Missing account.
|
||||||
#[display("missing account {_0}")]
|
#[display("missing account {_0}")]
|
||||||
@ -131,18 +103,6 @@ pub enum TrieWitnessError {
|
|||||||
MissingTargetNode(Nibbles),
|
MissingTargetNode(Nibbles),
|
||||||
}
|
}
|
||||||
|
|
||||||
impl From<StateProofError> for TrieWitnessError {
|
|
||||||
fn from(error: StateProofError) -> Self {
|
|
||||||
Self::Proof(error)
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
impl From<alloy_rlp::Error> for TrieWitnessError {
|
|
||||||
fn from(error: alloy_rlp::Error) -> Self {
|
|
||||||
Self::Rlp(error)
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
impl From<TrieWitnessError> for ProviderError {
|
impl From<TrieWitnessError> for ProviderError {
|
||||||
fn from(error: TrieWitnessError) -> Self {
|
fn from(error: TrieWitnessError) -> Self {
|
||||||
Self::TrieWitnessError(error.to_string())
|
Self::TrieWitnessError(error.to_string())
|
||||||
|
|||||||
Reference in New Issue
Block a user