alloy_rpc_types_eth/error.rs
1//! Commonly used errors for the `eth_` namespace.
2
3/// List of JSON-RPC error codes
4#[derive(Clone, Copy, Debug, PartialEq, Eq)]
5pub enum EthRpcErrorCode {
6 /// Failed to send transaction, See also <https://github.com/MetaMask/eth-rpc-errors/blob/main/src/error-constants.ts>
7 TransactionRejected,
8 /// Custom geth error code, <https://github.com/vapory-legacy/wiki/blob/master/JSON-RPC-Error-Codes-Improvement-Proposal.md>
9 ExecutionError,
10 /// <https://eips.ethereum.org/EIPS/eip-1898>
11 InvalidInput,
12 /// Thrown when a block wasn't found <https://github.com/ethereum/EIPs/blob/master/EIPS/eip-1898.md>
13 /// > If the block is not found, the callee SHOULD raise a JSON-RPC error (the recommended
14 /// > error code is -32001: Resource not found).
15 ResourceNotFound,
16 /// Thrown when querying for `finalized` or `safe` block before the merge transition is
17 /// finalized, <https://github.com/ethereum/execution-apis/blob/6d17705a875e52c26826124c2a8a15ed542aeca2/src/schemas/block.yaml#L109>
18 UnknownBlock,
19 /// Thrown when historical data is not available.
20 /// <https://eips.ethereum.org/EIPS/eip-4444#json-rpc-changes>
21 PrunedHistory,
22 /// Transaction confirmation timed out.
23 /// Specs <https://github.com/ethereum/EIPs/blob/master/EIPS/eip-7966.md#method-name>
24 TransactionConfirmationTimeout,
25}
26
27impl EthRpcErrorCode {
28 /// Returns the error code as `i32`
29 pub const fn code(&self) -> i32 {
30 match *self {
31 Self::TransactionRejected => -32003,
32 Self::ExecutionError => 3,
33 Self::InvalidInput => -32000,
34 Self::ResourceNotFound => -32001,
35 Self::UnknownBlock => -39001,
36 Self::PrunedHistory => 4444,
37 Self::TransactionConfirmationTimeout => 4,
38 }
39 }
40}