Skip to main content

mega_evme/common/
error.rs

1use alloy_primitives::{hex::FromHexError, BlockNumber, TxHash, B256};
2use alloy_provider::transport::TransportError;
3use mega_evm::{alloy_evm::block::BlockExecutionError, revm::bytecode::BytecodeDecodeError};
4
5/// Error types for the replay command
6#[derive(Debug, thiserror::Error)]
7pub enum EvmeError {
8    /// RPC transport error
9    #[error("RPC transport error: {0}")]
10    RpcTransportError(TransportError),
11
12    /// Transaction not found
13    #[error("Transaction not found: {0}")]
14    TransactionNotFound(TxHash),
15
16    /// Block not found
17    #[error("Block not found: {0}")]
18    BlockNotFound(BlockNumber),
19
20    /// Block execution error
21    #[error("Block execution error: {0}")]
22    BlockExecutionError(#[from] BlockExecutionError),
23
24    /// Invalid bytecode
25    #[error("Invalid bytecode: {0}")]
26    InvalidBytecode(#[from] BytecodeDecodeError),
27
28    /// Failed to read file
29    #[error("Failed to read file: {0}")]
30    FileRead(#[from] std::io::Error),
31
32    /// Invalid hex string
33    #[error("Invalid hex string: {0}")]
34    InvalidHex(#[from] FromHexError),
35
36    /// EVM execution error
37    #[error("EVM execution error: {0}")]
38    ExecutionError(String),
39
40    /// Invalid input
41    #[error("Invalid input: {0}")]
42    InvalidInput(String),
43
44    /// RPC error
45    #[error("RPC error: {0}")]
46    RpcError(String),
47
48    /// Fixture envelope error
49    #[error("Fixture error: {0}")]
50    FixtureError(String),
51
52    /// Unsupported transaction type
53    #[error("Unsupported transaction type: {0}")]
54    UnsupportedTxType(u8),
55
56    /// Code hash mismatch
57    #[error("Code hash mismatch: expected {expected}, computed {computed}")]
58    CodeHashMismatch {
59        /// Expected code hash from prestate
60        expected: B256,
61        /// Computed code hash from bytecode
62        computed: B256,
63    },
64
65    /// Other error
66    #[error("Other error: {0}")]
67    Other(String),
68}
69
70// Implement DBErrorMarker to allow EvmeError to be used as Database error type
71impl mega_evm::revm::database::DBErrorMarker for EvmeError {}
72
73/// Result type for the mega-evme command
74pub type Result<T> = std::result::Result<T, EvmeError>;