reth_engine_primitives/
error.rs1use alloc::boxed::Box;
2use alloy_rpc_types_engine::ForkchoiceUpdateError;
3use reth_errors::{BlockExecutionError, BlockValidationError, ConsensusError, ProviderError};
4use reth_execution_errors::InternalBlockExecutionError;
5
6#[derive(Debug, thiserror::Error)]
11pub enum BeaconOnNewPayloadError {
12 #[error("beacon consensus engine task stopped")]
14 EngineUnavailable,
15 #[error(transparent)]
17 Internal(Box<dyn core::error::Error + Send + Sync>),
18}
19
20impl BeaconOnNewPayloadError {
21 pub fn internal<E: core::error::Error + Send + Sync + 'static>(e: E) -> Self {
23 Self::Internal(Box::new(e))
24 }
25}
26
27#[derive(Debug, thiserror::Error)]
32pub enum BeaconForkChoiceUpdateError {
33 #[error("forkchoice update error: {0}")]
35 ForkchoiceUpdateError(#[from] ForkchoiceUpdateError),
36 #[error("beacon consensus engine task stopped")]
38 EngineUnavailable,
39 #[error(transparent)]
41 Internal(Box<dyn core::error::Error + Send + Sync>),
42}
43
44impl BeaconForkChoiceUpdateError {
45 pub fn internal<E: core::error::Error + Send + Sync + 'static>(e: E) -> Self {
47 Self::Internal(Box::new(e))
48 }
49}
50
51#[derive(Debug, thiserror::Error)]
53pub enum InsertBlockErrorKind {
54 #[error(transparent)]
56 Consensus(#[from] ConsensusError),
57 #[error(transparent)]
59 Execution(#[from] BlockExecutionError),
60 #[error(transparent)]
62 Provider(#[from] ProviderError),
63 #[error(transparent)]
65 Other(#[from] Box<dyn core::error::Error + Send + Sync + 'static>),
66}
67
68impl InsertBlockErrorKind {
69 pub const fn is_validation_error(&self) -> bool {
71 matches!(self, Self::Consensus(_) | Self::Execution(BlockExecutionError::Validation(_)))
72 }
73
74 pub fn ensure_validation_error(
82 self,
83 ) -> Result<InsertBlockValidationError, InsertBlockFatalError> {
84 match self {
85 Self::Consensus(err) => Ok(InsertBlockValidationError::Consensus(err)),
86 Self::Execution(err) => match err {
87 BlockExecutionError::Validation(err) => {
88 Ok(InsertBlockValidationError::Validation(err))
89 }
90 BlockExecutionError::Internal(error) => {
91 Err(InsertBlockFatalError::BlockExecutionError(error))
92 }
93 },
94 Self::Provider(err) => Err(InsertBlockFatalError::Provider(err)),
95 Self::Other(err) => Err(InternalBlockExecutionError::Other(err).into()),
96 }
97 }
98}
99
100#[derive(Debug, thiserror::Error)]
102pub enum InsertBlockFatalError {
103 #[error(transparent)]
105 Provider(#[from] ProviderError),
106 #[error(transparent)]
108 BlockExecutionError(#[from] InternalBlockExecutionError),
109}
110
111#[derive(Debug, thiserror::Error)]
113pub enum InsertBlockValidationError {
114 #[error(transparent)]
116 Consensus(#[from] ConsensusError),
117 #[error(transparent)]
119 Validation(#[from] BlockValidationError),
120}