revm_trace/
errors.rs

1//! Error types for EVM tracing and simulation
2//!
3//! This module defines a comprehensive error handling system that covers:
4//! - EVM initialization errors
5//! - Runtime execution errors
6//! - Token-related errors
7//! - Error conversion and propagation
8
9use thiserror::Error;
10
11/// Top-level error type for the EVM tracing system
12///
13/// Encompasses all possible errors that can occur during EVM operations,
14/// providing a unified error handling interface for users.
15#[derive(Debug, Clone, Error)]
16pub enum EvmError {
17    /// Errors occurring during EVM initialization
18    #[error("Failed to initialize EVM: {0}")]
19    Init(#[from] InitError),
20
21    /// Errors occurring during transaction execution
22    #[error("Error during execution: {0}")]
23    Runtime(#[from] RuntimeError),
24
25    /// Errors related to token operations
26    #[error("Token error: {0}")]
27    Token(#[from] TokenError),
28
29    /// Errors related to override operations
30    #[error("Override error: {0}")]
31    OverrideError(String),
32}
33
34/// Initialization-specific errors
35///
36/// These errors occur during the setup phase of the EVM,
37/// typically related to network connectivity and configuration.
38#[derive(Debug, Clone, Error)]
39pub enum InitError {
40    /// Invalid or malformed RPC URL
41    #[error("Invalid RPC URL: {0}")]
42    InvalidRpcUrl(String),
43
44    /// Database setup or connection errors
45    #[error("Database initialization failed: {0}")]
46    DatabaseError(String),
47
48    /// WebSocket connection establishment errors
49    #[error("WebSocket connection failed: {0}")]
50    WsConnection(String),
51
52    /// Chain ID retrieval or validation errors
53    #[error("Failed to get chain ID: {0}")]
54    ChainId(String),
55
56    /// Errors fetching the chain ID from the provider
57    #[error("Failed to fetch chain ID: {0}")]
58    ChainIdFetchError(String),
59
60    /// Errors related to block fetching
61    #[error("Failed to fetch block: {0}")]
62    BlockFetchError(String),
63
64    /// Errors related to block not found
65    #[error("Block not found: {0}")]
66    BlockNotFound(String),
67}
68
69/// Runtime execution errors
70///
71/// These errors occur during actual transaction execution,
72/// including gas issues, reverts, and state access problems.
73#[derive(Debug, Clone, Error)]
74pub enum RuntimeError {
75    /// General transaction execution failures
76    #[error("Transaction execution failed: {0}")]
77    ExecutionFailed(String),
78
79    /// Errors accessing account information
80    #[error("Account access error: {0}")]
81    AccountAccess(String),
82
83    /// Errors accessing storage slots
84    #[error("Slot access error: {0}")]
85    SlotAccess(String),
86
87    /// Transaction ran out of gas
88    #[error("Out of gas")]
89    OutOfGas,
90
91    /// Transaction explicitly reverted
92    #[error("Reverted: {0}")]
93    Revert(String),
94
95    /// Transaction reverted due to insufficient balance
96    #[error("Reverted due to insufficient balance: {0}")]
97    NoTokioRuntime(String),
98
99    /// Errors decoding data from the EVM
100    #[error("Failed to decode data: {0}")]
101    DecodeError(String),
102}
103
104#[derive(Debug, Error)]
105pub enum BalanceError {
106    /// Failed to decode balance of a token holder
107    ///
108    /// # Fields
109    /// * `address` - Token contract address
110    /// * `holder` - Token holder address
111    /// * `reason` - Detailed error message
112    #[error("Failed to decode balance for {holder} in token {address}: {reason}")]
113    BalanceDecode {
114        address: String,
115        holder: String,
116        reason: String,
117    },
118
119    /// Failed to get balance of a owner
120    ///
121    /// # Fields
122    /// * `holder` - Holder address
123    /// * `reason` - Detailed error message
124    ///
125    #[error("Failed to get balance of {holder}: {reason}")]
126    BalanceGetError { holder: String, reason: String },
127}
128
129/// Token-specific errors
130///
131/// These errors occur during ERC20 token operations,
132/// including symbol and decimals queries, and general token calls.
133#[derive(Debug, Clone, Error)]
134pub enum TokenError {
135    /// General token-related errors
136    ///
137    /// This variant wraps any error that does not fit into the specific token error categories.
138    #[error("Token error: {0}")]
139    AnyhowError(String),
140
141    /// Failed to decode token name
142    ///
143    /// # Fields
144    /// * `address` - Token contract address
145    /// * `reason` - Detailed error message
146    #[error("Failed to decode token name for {address}: {reason}")]
147    NameDecode { address: String, reason: String },
148
149    /// Failed to decode token symbol
150    ///
151    /// # Fields
152    /// * `address` - Token contract address
153    /// * `reason` - Detailed error message
154    #[error("Failed to decode token symbol for {address}: {reason}")]
155    SymbolDecode { address: String, reason: String },
156
157    /// Failed to decode token decimals
158    ///
159    /// # Fields
160    /// * `address` - Token contract address
161    /// * `reason` - Detailed error message
162    #[error("Failed to decode token decimals for {address}: {reason}")]
163    DecimalsDecode { address: String, reason: String },
164
165    /// Failed to decode token total supply
166    ///
167    /// # Fields
168    /// * `address` - Token contract address
169    /// * `reason` - Detailed error message
170    #[error("Failed to decode token total supply for {address}: {reason}")]
171    TotalSupplyDecode { address: String, reason: String },
172
173    /// Failed to decode balance of a token holder
174    ///
175    /// # Fields
176    /// * `address` - Token contract address
177    /// * `holder` - Token holder address
178    /// * `reason` - Detailed error message
179    #[error("Failed to decode balance for {holder} in token {address}: {reason}")]
180    BalanceDecode {
181        address: String,
182        holder: String,
183        reason: String,
184    },
185
186    /// General token query failures
187    ///
188    /// # Fields
189    /// * `address` - Token contract address
190    /// * `reason` - Detailed error message
191    #[error("Failed to query token {address}: {reason}")]
192    QueryFailed { address: String, reason: String },
193
194    /// Token call reverted
195    ///
196    /// # Fields
197    /// * `address` - Token contract address
198    #[error("Token call reverted for {address}")]
199    CallReverted { address: String },
200}