reth_errors/
error.rs

1use alloc::{boxed::Box, string::ToString};
2use core::fmt::Display;
3use reth_consensus::ConsensusError;
4use reth_execution_errors::BlockExecutionError;
5use reth_storage_errors::{db::DatabaseError, provider::ProviderError};
6
7/// Result alias for [`RethError`].
8pub type RethResult<T> = Result<T, RethError>;
9
10/// Core error variants possible when interacting with the blockchain.
11///
12/// This enum encapsulates various error types that can occur during blockchain interactions.
13///
14/// It allows for structured error handling based on the nature of the encountered issue.
15#[derive(Debug, thiserror::Error)]
16pub enum RethError {
17    /// Error encountered during block execution.
18    #[error(transparent)]
19    Execution(#[from] BlockExecutionError),
20
21    /// Consensus-related errors.
22    #[error(transparent)]
23    Consensus(#[from] ConsensusError),
24
25    /// Database-related errors.
26    #[error(transparent)]
27    Database(#[from] DatabaseError),
28
29    /// Errors originating from providers.
30    #[error(transparent)]
31    Provider(#[from] ProviderError),
32
33    /// Any other error.
34    #[error(transparent)]
35    Other(Box<dyn core::error::Error + Send + Sync>),
36}
37
38impl RethError {
39    /// Create a new `RethError` from a given error.
40    pub fn other<E>(error: E) -> Self
41    where
42        E: core::error::Error + Send + Sync + 'static,
43    {
44        Self::Other(Box::new(error))
45    }
46
47    /// Create a new `RethError` from a given message.
48    pub fn msg(msg: impl Display) -> Self {
49        Self::Other(msg.to_string().into())
50    }
51}
52
53// Some types are used a lot. Make sure they don't unintentionally get bigger.
54#[cfg(all(target_arch = "x86_64", target_pointer_width = "64"))]
55mod size_asserts {
56    use super::*;
57
58    macro_rules! static_assert_size {
59        ($t:ty, $sz:expr) => {
60            const _: [(); $sz] = [(); core::mem::size_of::<$t>()];
61        };
62    }
63
64    static_assert_size!(RethError, 56);
65    static_assert_size!(BlockExecutionError, 56);
66    static_assert_size!(ConsensusError, 48);
67    static_assert_size!(DatabaseError, 32);
68    static_assert_size!(ProviderError, 48);
69}