From b3f31fc6f2fa0c15f7287ac83ba608a8513ffef1 Mon Sep 17 00:00:00 2001 From: Matthias Seitz Date: Tue, 25 Jun 2024 13:42:59 +0200 Subject: [PATCH] feat: add helper function to mape EVMError's Database error variant (#1567) --- crates/primitives/src/result.rs | 16 ++++++++++++++++ 1 file changed, 16 insertions(+) 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)> {