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}
23
24impl EthRpcErrorCode {
25 /// Returns the error code as `i32`
26 pub const fn code(&self) -> i32 {
27 match *self {
28 Self::TransactionRejected => -32003,
29 Self::ExecutionError => 3,
30 Self::InvalidInput => -32000,
31 Self::ResourceNotFound => -32001,
32 Self::UnknownBlock => -39001,
33 Self::PrunedHistory => 4444,
34 }
35 }
36}