Skip to content

Commit

Permalink
Use Display impl instead of deprecated description method of `Err…
Browse files Browse the repository at this point in the history
…or` trait (#286)

* Use Display impl instead of deprecated description method of Error trait

* make Display impl works in no_std env
  • Loading branch information
koushiro authored May 20, 2024
1 parent a376f95 commit 1218997
Showing 1 changed file with 8 additions and 12 deletions.
20 changes: 8 additions & 12 deletions interpreter/src/error.rs
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
use crate::Opcode;
use alloc::borrow::Cow;
use core::fmt;

/// Capture represents the result of execution.
#[derive(Clone, Copy, Debug, Eq, PartialEq)]
Expand Down Expand Up @@ -54,23 +55,18 @@ impl From<ExitError> for ExitResult {
}

#[cfg(feature = "std")]
impl std::error::Error for ExitError {
fn description(&self) -> &str {
impl std::error::Error for ExitError {}

impl fmt::Display for ExitError {
fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
match self {
Self::Exception(_) => "EVM exit exception",
Self::Reverted => "EVM internal revert",
Self::Fatal(_) => "EVM fatal error",
Self::Exception(_) => f.write_str("EVM exit exception"),
Self::Reverted => f.write_str("EVM internal revert"),
Self::Fatal(_) => f.write_str("EVM fatal error"),
}
}
}

#[cfg(feature = "std")]
impl std::fmt::Display for ExitError {
fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result {
write!(f, "{self:?}")
}
}

/// Exit succeed reason.
#[derive(Clone, Copy, Debug, Eq, PartialEq)]
#[cfg_attr(
Expand Down

0 comments on commit 1218997

Please sign in to comment.