diff --git a/crates/primitives/src/result.rs b/crates/primitives/src/result.rs index 2a61883a89..c7a4469e71 100644 --- a/crates/primitives/src/result.rs +++ b/crates/primitives/src/result.rs @@ -152,6 +152,22 @@ pub enum EVMError { Precompile(String), } +impl EVMError { + /// Maps a `DBError` to a new error type using the provided closure, leaving other variants unchanged. + pub fn map_db_err(self, op: F) -> EVMError + where + F: FnOnce(DBError) -> E, + { + match self { + Self::Transaction(e) => EVMError::Transaction(e), + Self::Header(e) => EVMError::Header(e), + Self::Database(e) => EVMError::Database(op(e)), + Self::Precompile(e) => EVMError::Precompile(e), + Self::Custom(e) => EVMError::Custom(e), + } + } +} + #[cfg(feature = "std")] impl std::error::Error for EVMError { fn source(&self) -> Option<&(dyn std::error::Error + 'static)> {