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)