From 781c8ccebafac5acd02afcc75e04449c65b04d48 Mon Sep 17 00:00:00 2001 From: Yiannis Marangos Date: Fri, 28 Jul 2023 12:37:27 +0300 Subject: [PATCH] feat: Implement `Error` for EVMError (#559) --- crates/primitives/src/result.rs | 17 +++++++++++++++++ 1 file changed, 17 insertions(+) diff --git a/crates/primitives/src/result.rs b/crates/primitives/src/result.rs index ee05495c27..d38604f979 100644 --- a/crates/primitives/src/result.rs +++ b/crates/primitives/src/result.rs @@ -1,6 +1,7 @@ use crate::{Log, State, B160}; use alloc::vec::Vec; use bytes::Bytes; +use core::fmt; use ruint::aliases::U256; pub type EVMResult = core::result::Result>; @@ -128,6 +129,22 @@ pub enum EVMError { Database(DBError), } +#[cfg(feature = "std")] +impl std::error::Error for EVMError where Self: fmt::Debug + fmt::Display {} + +impl fmt::Display for EVMError +where + DBError: fmt::Display, +{ + fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result { + match self { + EVMError::Transaction(v) => write!(f, "Transaction error: {:?}", v), + EVMError::PrevrandaoNotSet => f.write_str("Prevrandao not set"), + EVMError::Database(v) => write!(f, "Database error: {}", v), + } + } +} + impl From for EVMError { fn from(invalid: InvalidTransaction) -> Self { EVMError::Transaction(invalid)