1use reth_blockchain_tree_api::error::{BlockchainTreeError, CanonicalError};
2use reth_consensus::ConsensusError;
3use reth_execution_errors::BlockExecutionError;
4use reth_fs_util::FsPathError;
5use reth_storage_errors::{db::DatabaseError, provider::ProviderError};
6use std::fmt::Display;
7
8pub type RethResult<T> = Result<T, RethError>;
10
11#[derive(Debug, thiserror::Error)]
17pub enum RethError {
18 #[error(transparent)]
20 Execution(#[from] BlockExecutionError),
21
22 #[error(transparent)]
24 Consensus(#[from] ConsensusError),
25
26 #[error(transparent)]
28 Database(#[from] DatabaseError),
29
30 #[error(transparent)]
32 Provider(#[from] ProviderError),
33
34 #[error(transparent)]
36 Canonical(#[from] CanonicalError),
37
38 #[error(transparent)]
40 Other(Box<dyn core::error::Error + Send + Sync>),
41}
42
43impl RethError {
44 pub fn other<E>(error: E) -> Self
46 where
47 E: core::error::Error + Send + Sync + 'static,
48 {
49 Self::Other(Box::new(error))
50 }
51
52 pub fn msg(msg: impl Display) -> Self {
54 Self::Other(msg.to_string().into())
55 }
56}
57
58impl From<BlockchainTreeError> for RethError {
59 fn from(error: BlockchainTreeError) -> Self {
60 Self::Canonical(CanonicalError::BlockchainTree(error))
61 }
62}
63
64impl From<FsPathError> for RethError {
65 fn from(err: FsPathError) -> Self {
66 Self::other(err)
67 }
68}
69
70#[cfg(all(target_arch = "x86_64", target_pointer_width = "64"))]
72mod size_asserts {
73 use super::*;
74
75 macro_rules! static_assert_size {
76 ($t:ty, $sz:expr) => {
77 const _: [(); $sz] = [(); std::mem::size_of::<$t>()];
78 };
79 }
80
81 static_assert_size!(RethError, 64);
82 static_assert_size!(BlockExecutionError, 56);
83 static_assert_size!(ConsensusError, 48);
84 static_assert_size!(DatabaseError, 32);
85 static_assert_size!(ProviderError, 48);
86 static_assert_size!(CanonicalError, 56);
87}