fix: rm redundant revert in error message (#14215)

This commit is contained in:
Matthias Seitz
2025-02-04 18:40:42 +01:00
committed by GitHub
parent 97ffdfa563
commit f43cf9c18a

View File

@ -8,7 +8,7 @@ use core::time::Duration;
use alloy_eips::BlockId; use alloy_eips::BlockId;
use alloy_primitives::{Address, Bytes, U256}; use alloy_primitives::{Address, Bytes, U256};
use alloy_rpc_types_eth::{error::EthRpcErrorCode, request::TransactionInputError, BlockError}; use alloy_rpc_types_eth::{error::EthRpcErrorCode, request::TransactionInputError, BlockError};
use alloy_sol_types::decode_revert_reason; use alloy_sol_types::{ContractError, RevertReason};
use reth_errors::RethError; use reth_errors::RethError;
use reth_primitives_traits::transaction::signed::RecoveryError; use reth_primitives_traits::transaction::signed::RecoveryError;
use reth_rpc_server_types::result::{ use reth_rpc_server_types::result::{
@ -615,8 +615,14 @@ impl RevertError {
impl std::fmt::Display for RevertError { impl std::fmt::Display for RevertError {
fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result { fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result {
f.write_str("execution reverted")?; f.write_str("execution reverted")?;
if let Some(reason) = self.output.as_ref().and_then(|bytes| decode_revert_reason(bytes)) { if let Some(reason) = self.output.as_ref().and_then(|out| RevertReason::decode(out)) {
write!(f, ": {reason}")?; let error = reason.to_string();
let mut error = error.as_str();
if matches!(reason, RevertReason::ContractError(ContractError::Revert(_))) {
// we strip redundant `revert: ` prefix from the revert reason
error = error.trim_start_matches("revert: ");
}
write!(f, ": {error}")?;
} }
Ok(()) Ok(())
} }
@ -768,9 +774,9 @@ pub fn ensure_success(result: ExecutionResult) -> EthResult<Bytes> {
#[cfg(test)] #[cfg(test)]
mod tests { mod tests {
use revm_primitives::b256;
use super::*; use super::*;
use alloy_sol_types::{Revert, SolError};
use revm_primitives::b256;
#[test] #[test]
fn timed_out_error() { fn timed_out_error() {
@ -805,4 +811,12 @@ mod tests {
EthApiError::HeaderNotFound(BlockId::finalized()).into(); EthApiError::HeaderNotFound(BlockId::finalized()).into();
assert_eq!(err.message(), "block not found: finalized"); assert_eq!(err.message(), "block not found: finalized");
} }
#[test]
fn revert_err_display() {
let revert = Revert::from("test_revert_reason");
let err = RevertError::new(revert.abi_encode().into());
let msg = err.to_string();
assert_eq!(msg, "execution reverted: test_revert_reason");
}
} }