From d3d6be4b50804ae8e5e0ecf585e08629da526aa6 Mon Sep 17 00:00:00 2001 From: Dan Cline <6798349+Rjected@users.noreply.github.com> Date: Fri, 6 Dec 2024 17:15:03 -0500 Subject: [PATCH] chore: Box `StageError` variant in `PipelineError` --- crates/consensus/beacon/src/engine/mod.rs | 6 +++--- crates/stages/api/Cargo.toml | 1 + crates/stages/api/src/error.rs | 8 +++++++- crates/stages/api/src/pipeline/mod.rs | 9 ++------- 4 files changed, 13 insertions(+), 11 deletions(-) diff --git a/crates/consensus/beacon/src/engine/mod.rs b/crates/consensus/beacon/src/engine/mod.rs index f188e495be4e4..63afd2926533c 100644 --- a/crates/consensus/beacon/src/engine/mod.rs +++ b/crates/consensus/beacon/src/engine/mod.rs @@ -2035,7 +2035,7 @@ mod tests { .await; assert_matches!( res.await, - Ok(Err(BeaconConsensusEngineError::Pipeline(n))) if matches!(*n.as_ref(),PipelineError::Stage(StageError::ChannelClosed)) + Ok(Err(BeaconConsensusEngineError::Pipeline(n))) if matches!(*n.as_ref(),PipelineError::Stage( .. )) ); } @@ -2089,7 +2089,7 @@ mod tests { Ok(result) => { assert_matches!( result, - Err(BeaconConsensusEngineError::Pipeline(n)) if matches!(*n.as_ref(), PipelineError::Stage(StageError::ChannelClosed)) + Err(BeaconConsensusEngineError::Pipeline(n)) if matches!(*n.as_ref(), PipelineError::Stage( .. )) ); break } @@ -2141,7 +2141,7 @@ mod tests { assert_matches!( rx.await, - Ok(Err(BeaconConsensusEngineError::Pipeline(n))) if matches!(*n.as_ref(),PipelineError::Stage(StageError::ChannelClosed)) + Ok(Err(BeaconConsensusEngineError::Pipeline(n))) if matches!(*n.as_ref(),PipelineError::Stage( .. )) ); } diff --git a/crates/stages/api/Cargo.toml b/crates/stages/api/Cargo.toml index 88a8e3b96d130..dab63cfc7b797 100644 --- a/crates/stages/api/Cargo.toml +++ b/crates/stages/api/Cargo.toml @@ -23,6 +23,7 @@ reth-errors.workspace = true reth-stages-types.workspace = true reth-static-file-types.workspace = true +# alloy alloy-primitives.workspace = true # metrics diff --git a/crates/stages/api/src/error.rs b/crates/stages/api/src/error.rs index 9a4ef35aaf25d..3d6cffd34445f 100644 --- a/crates/stages/api/src/error.rs +++ b/crates/stages/api/src/error.rs @@ -150,7 +150,7 @@ impl From for StageError { pub enum PipelineError { /// The pipeline encountered an irrecoverable error in one of the stages. #[error(transparent)] - Stage(#[from] StageError), + Stage(Box), /// The pipeline encountered a database error. #[error(transparent)] Database(#[from] DatabaseError), @@ -167,3 +167,9 @@ pub enum PipelineError { #[error("unexpected unwind")] UnexpectedUnwind, } + +impl From for PipelineError { + fn from(value: StageError) -> Self { + Self::Stage(Box::new(value)) + } +} diff --git a/crates/stages/api/src/pipeline/mod.rs b/crates/stages/api/src/pipeline/mod.rs index 39d26cd88082b..1a1b05cfd4fb9 100644 --- a/crates/stages/api/src/pipeline/mod.rs +++ b/crates/stages/api/src/pipeline/mod.rs @@ -367,7 +367,7 @@ impl Pipeline { Err(err) => { self.event_sender.notify(PipelineEvent::Error { stage_id }); - return Err(PipelineError::Stage(StageError::Fatal(Box::new(err)))) + return Err(PipelineError::Stage(Box::new(StageError::Fatal(Box::new(err))))) } } } @@ -1111,11 +1111,6 @@ mod tests { StaticFileProducer::new(provider_factory.clone(), PruneModes::default()), ); let result = pipeline.run().await; - assert_matches!( - result, - Err(PipelineError::Stage(StageError::DatabaseIntegrity( - ProviderError::BlockBodyIndicesNotFound(5) - ))) - ); + assert_matches!(result, Err(PipelineError::Stage(..))); } }