mirror of
https://github.com/paradigmxyz/reth.git
synced 2026-02-11 07:25:09 -05:00
refactor: replace OP error variant with general purpose error (#7844)
Co-authored-by: Oliver Nordbjerg <onbjerg@users.noreply.github.com>
This commit is contained in:
committed by
GitHub
parent
1f84c27c35
commit
784d8dc597
@@ -5,6 +5,7 @@ use reth_beacon_consensus::{BeaconForkChoiceUpdateError, BeaconOnNewPayloadError
|
||||
use reth_engine_primitives::EngineObjectValidationError;
|
||||
use reth_payload_builder::error::PayloadBuilderError;
|
||||
use reth_primitives::{B256, U256};
|
||||
use reth_rpc_types::ToRpcError;
|
||||
use thiserror::Error;
|
||||
|
||||
/// The Engine API result type
|
||||
@@ -86,11 +87,16 @@ pub enum EngineApiError {
|
||||
/// The payload or attributes are known to be malformed before processing.
|
||||
#[error(transparent)]
|
||||
EngineObjectValidationError(#[from] EngineObjectValidationError),
|
||||
/// If the optimism feature flag is enabled, the payload attributes must have a present
|
||||
/// gas limit for the forkchoice updated method.
|
||||
#[cfg(feature = "optimism")]
|
||||
#[error("Missing gas limit in payload attributes")]
|
||||
MissingGasLimitInPayloadAttributes,
|
||||
/// Any other error
|
||||
#[error("{0}")]
|
||||
Other(Box<dyn ToRpcError>),
|
||||
}
|
||||
|
||||
impl EngineApiError {
|
||||
/// Crates a new [EngineApiError::Other] variant.
|
||||
pub fn other<E: ToRpcError>(err: E) -> Self {
|
||||
Self::Other(Box::new(err))
|
||||
}
|
||||
}
|
||||
|
||||
/// Helper type to represent the `error` field in the error response:
|
||||
@@ -188,15 +194,6 @@ impl From<EngineApiError> for jsonrpsee_types::error::ErrorObject<'static> {
|
||||
)
|
||||
}
|
||||
},
|
||||
// Optimism errors
|
||||
#[cfg(feature = "optimism")]
|
||||
EngineApiError::MissingGasLimitInPayloadAttributes => {
|
||||
jsonrpsee_types::error::ErrorObject::owned(
|
||||
INVALID_PARAMS_CODE,
|
||||
INVALID_PARAMS_MSG,
|
||||
Some(ErrorData::new(error)),
|
||||
)
|
||||
}
|
||||
// Any other server error
|
||||
EngineApiError::TerminalTD { .. } |
|
||||
EngineApiError::TerminalBlockHash { .. } |
|
||||
@@ -206,6 +203,7 @@ impl From<EngineApiError> for jsonrpsee_types::error::ErrorObject<'static> {
|
||||
SERVER_ERROR_MSG,
|
||||
Some(ErrorData::new(error)),
|
||||
),
|
||||
EngineApiError::Other(err) => err.to_rpc_error(),
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
9
crates/rpc/rpc-types/src/eth/error.rs
Normal file
9
crates/rpc/rpc-types/src/eth/error.rs
Normal file
@@ -0,0 +1,9 @@
|
||||
//! Implementation specific Errors for the `eth_` namespace.
|
||||
|
||||
use jsonrpsee_types::ErrorObject;
|
||||
|
||||
/// A tait to convert an error to an RPC error.
|
||||
pub trait ToRpcError: std::error::Error + Send + Sync + 'static {
|
||||
/// Converts the error to a JSON-RPC error object.
|
||||
fn to_rpc_error(&self) -> ErrorObject<'static>;
|
||||
}
|
||||
@@ -1,5 +1,6 @@
|
||||
//! Ethereum related types
|
||||
|
||||
pub(crate) mod error;
|
||||
pub mod transaction;
|
||||
|
||||
// re-export
|
||||
|
||||
@@ -37,6 +37,7 @@ pub use eth::{
|
||||
engine::{
|
||||
ExecutionPayload, ExecutionPayloadV1, ExecutionPayloadV2, ExecutionPayloadV3, PayloadError,
|
||||
},
|
||||
error::ToRpcError,
|
||||
transaction::{self, TransactionKind, TransactionRequest, TypedTransactionRequest},
|
||||
};
|
||||
|
||||
|
||||
@@ -706,7 +706,7 @@ mod u256_numeric_string {
|
||||
match val {
|
||||
serde_json::Value::String(s) => {
|
||||
if let Ok(val) = s.parse::<u128>() {
|
||||
return Ok(U256::from(val))
|
||||
return Ok(U256::from(val));
|
||||
}
|
||||
U256::from_str(&s).map_err(de::Error::custom)
|
||||
}
|
||||
|
||||
@@ -6,7 +6,9 @@ use jsonrpsee::types::{error::CALL_EXECUTION_FAILED_CODE, ErrorObject};
|
||||
use reth_interfaces::RethError;
|
||||
use reth_primitives::{revm_primitives::InvalidHeader, Address, Bytes, U256};
|
||||
use reth_revm::tracing::{js::JsInspectorError, MuxError};
|
||||
use reth_rpc_types::{error::EthRpcErrorCode, request::TransactionInputError, BlockError};
|
||||
use reth_rpc_types::{
|
||||
error::EthRpcErrorCode, request::TransactionInputError, BlockError, ToRpcError,
|
||||
};
|
||||
use reth_transaction_pool::error::{
|
||||
Eip4844PoolTransactionError, InvalidPoolTransactionError, PoolError, PoolErrorKind,
|
||||
PoolTransactionError,
|
||||
@@ -17,12 +19,6 @@ use std::time::Duration;
|
||||
/// Result alias
|
||||
pub type EthResult<T> = Result<T, EthApiError>;
|
||||
|
||||
/// A tait for custom rpc errors used by [EthApiError::Other].
|
||||
pub trait ToRpcError: std::error::Error + Send + Sync + 'static {
|
||||
/// Converts the error to a JSON-RPC error object.
|
||||
fn to_rpc_error(&self) -> ErrorObject<'static>;
|
||||
}
|
||||
|
||||
/// Errors that can occur when interacting with the `eth_` namespace
|
||||
#[derive(Debug, thiserror::Error)]
|
||||
pub enum EthApiError {
|
||||
|
||||
@@ -1,11 +1,9 @@
|
||||
//! Optimism specific types.
|
||||
|
||||
use jsonrpsee::types::ErrorObject;
|
||||
use reth_rpc_types::ToRpcError;
|
||||
|
||||
use crate::{
|
||||
eth::error::{EthApiError, ToRpcError},
|
||||
result::internal_rpc_err,
|
||||
};
|
||||
use crate::{eth::error::EthApiError, result::internal_rpc_err};
|
||||
|
||||
/// Eth Optimism Api Error
|
||||
#[cfg(feature = "optimism")]
|
||||
|
||||
Reference in New Issue
Block a user