alloy_json_rpc

Struct ErrorPayload

source
pub struct ErrorPayload<ErrData = Box<RawValue>> {
    pub code: i64,
    pub message: Cow<'static, str>,
    pub data: Option<ErrData>,
}
Expand description

A JSON-RPC 2.0 error object.

This response indicates that the server received and handled the request, but that there was an error in the processing of it. The error should be included in the message field of the response payload.

Fields§

§code: i64

The error code.

§message: Cow<'static, str>

The error message (if any).

§data: Option<ErrData>

The error data (if any).

Implementations§

source§

impl<E> ErrorPayload<E>

source

pub const fn parse_error() -> Self

Create a new error payload for a parse error.

source

pub const fn invalid_request() -> Self

Create a new error payload for an invalid request.

source

pub const fn method_not_found() -> Self

Create a new error payload for a method not found error.

source

pub const fn invalid_params() -> Self

Create a new error payload for an invalid params error.

source

pub const fn internal_error() -> Self

Create a new error payload for an internal error.

source

pub const fn internal_error_message(message: Cow<'static, str>) -> Self

Create a new error payload for an internal error with a custom message.

source

pub const fn internal_error_with_obj(data: E) -> Self
where E: RpcObject,

Create a new error payload for an internal error with a custom message and additional data.

source

pub const fn internal_error_with_message_and_obj( message: Cow<'static, str>, data: E, ) -> Self
where E: RpcObject,

Create a new error payload for an internal error with a custom message

source

pub fn is_retry_err(&self) -> bool

Analyzes the ErrorPayload and decides if the request should be retried based on the error code or the message.

source§

impl<E> ErrorPayload<E>
where E: RpcObject,

source

pub fn serialize_payload(&self) -> Result<ErrorPayload>

Serialize the inner data into a RawValue.

source§

impl ErrorPayload<&RawValue>

source

pub fn into_owned(self) -> ErrorPayload

Convert this borrowed error payload into an owned payload by copying the data from the deserializer (if necessary).

source§

impl<'a, Data> ErrorPayload<Data>
where Data: Borrow<RawValue> + 'a,

source

pub fn try_data_as<T: Deserialize<'a>>(&'a self) -> Option<Result<T>>

Deserialize the error’s data field, borrowing from the data field if necessary.

§Returns
  • None if the error has no data field.
  • Some(Ok(data)) if the error has a data field that can be deserialized.
  • Some(Err(err)) if the error has a data field that can’t be deserialized.
source

pub fn deser_data<T: DeserializeOwned>(self) -> Result<ErrorPayload<T>, Self>

Attempt to deserialize the data field.

§Returns
  • Ok(ErrorPayload<T>) if the data field can be deserialized
  • Err(self) if the data field can’t be deserialized, or if there is no data field.
source

pub fn as_revert_data(&self) -> Option<Bytes>

Attempt to extract revert data from the JsonRpcError be recursively traversing the error’s data field

This returns the first hex it finds in the data object, and its behavior may change with serde_json internal changes.

If no hex object is found, it will return an empty bytes IFF the error is a revert

Inspired by ethers-js logic: https://github.com/ethers-io/ethers.js/blob/9f990c57f0486728902d4b8e049536f2bb3487ee/packages/providers/src.ts/json-rpc-provider.ts#L25-L53

source

pub fn as_decoded_error<E: SolInterface>(&self, validate: bool) -> Option<E>

Extracts revert data and tries decoding it into given custom errors set.

Trait Implementations§

source§

impl<ErrData: Clone> Clone for ErrorPayload<ErrData>

source§

fn clone(&self) -> ErrorPayload<ErrData>

Returns a copy of the value. Read more
1.0.0 · source§

fn clone_from(&mut self, source: &Self)

Performs copy-assignment from source. Read more
source§

impl<ErrData: Debug> Debug for ErrorPayload<ErrData>

source§

fn fmt(&self, f: &mut Formatter<'_>) -> Result

Formats the value using the given formatter. Read more
source§

impl<'de, ErrData: Deserialize<'de>> Deserialize<'de> for ErrorPayload<ErrData>

source§

fn deserialize<D>(deserializer: D) -> Result<Self, D::Error>
where D: Deserializer<'de>,

Deserialize this value from the given Serde deserializer. Read more
source§

impl<ErrData: Display> Display for ErrorPayload<ErrData>

source§

fn fmt(&self, f: &mut Formatter<'_>) -> Result

Formats the value using the given formatter. Read more
source§

impl<T> From<T> for ErrorPayload<T>
where T: Error + RpcObject,

source§

fn from(value: T) -> Self

Converts to this type from the input type.
source§

impl<ErrData: PartialEq> PartialEq for ErrorPayload<ErrData>

source§

fn eq(&self, other: &ErrorPayload<ErrData>) -> bool

Tests for self and other values to be equal, and is used by ==.
1.0.0 · source§

fn ne(&self, other: &Rhs) -> bool

Tests for !=. The default implementation is almost always sufficient, and should not be overridden without very good reason.
source§

impl<ErrData> Serialize for ErrorPayload<ErrData>
where ErrData: Serialize,

source§

fn serialize<__S>(&self, __serializer: __S) -> Result<__S::Ok, __S::Error>
where __S: Serializer,

Serialize this value into the given Serde serializer. Read more
source§

impl<ErrData: Eq> Eq for ErrorPayload<ErrData>

source§

impl<ErrData> StructuralPartialEq for ErrorPayload<ErrData>

Auto Trait Implementations§

§

impl<ErrData> Freeze for ErrorPayload<ErrData>
where ErrData: Freeze,

§

impl<ErrData> RefUnwindSafe for ErrorPayload<ErrData>
where ErrData: RefUnwindSafe,

§

impl<ErrData> Send for ErrorPayload<ErrData>
where ErrData: Send,

§

impl<ErrData> Sync for ErrorPayload<ErrData>
where ErrData: Sync,

§

impl<ErrData> Unpin for ErrorPayload<ErrData>
where ErrData: Unpin,

§

impl<ErrData> UnwindSafe for ErrorPayload<ErrData>
where ErrData: UnwindSafe,

Blanket Implementations§

source§

impl<T> Any for T
where T: 'static + ?Sized,

source§

fn type_id(&self) -> TypeId

Gets the TypeId of self. Read more
source§

impl<T> Borrow<T> for T
where T: ?Sized,

source§

fn borrow(&self) -> &T

Immutably borrows from an owned value. Read more
source§

impl<T> BorrowMut<T> for T
where T: ?Sized,

source§

fn borrow_mut(&mut self) -> &mut T

Mutably borrows from an owned value. Read more
source§

impl<T> CloneToUninit for T
where T: Clone,

source§

unsafe fn clone_to_uninit(&self, dst: *mut T)

🔬This is a nightly-only experimental API. (clone_to_uninit)
Performs copy-assignment from self to dst. Read more
source§

impl<Q, K> Equivalent<K> for Q
where Q: Eq + ?Sized, K: Borrow<Q> + ?Sized,

source§

fn equivalent(&self, key: &K) -> bool

Checks if this value is equivalent to the given key. Read more
source§

impl<T> From<T> for T

source§

fn from(t: T) -> T

Returns the argument unchanged.

source§

impl<T> Instrument for T

source§

fn instrument(self, span: Span) -> Instrumented<Self>

Instruments this type with the provided Span, returning an Instrumented wrapper. Read more
source§

fn in_current_span(self) -> Instrumented<Self>

Instruments this type with the current Span, returning an Instrumented wrapper. Read more
source§

impl<T, U> Into<U> for T
where U: From<T>,

source§

fn into(self) -> U

Calls U::from(self).

That is, this conversion is whatever the implementation of From<T> for U chooses to do.

source§

impl<T> ToOwned for T
where T: Clone,

source§

type Owned = T

The resulting type after obtaining ownership.
source§

fn to_owned(&self) -> T

Creates owned data from borrowed data, usually by cloning. Read more
source§

fn clone_into(&self, target: &mut T)

Uses borrowed data to replace owned data, usually by cloning. Read more
source§

impl<T> ToString for T
where T: Display + ?Sized,

source§

default fn to_string(&self) -> String

Converts the given value to a String. Read more
source§

impl<T, U> TryFrom<U> for T
where U: Into<T>,

source§

type Error = Infallible

The type returned in the event of a conversion error.
source§

fn try_from(value: U) -> Result<T, <T as TryFrom<U>>::Error>

Performs the conversion.
source§

impl<T, U> TryInto<U> for T
where U: TryFrom<T>,

source§

type Error = <U as TryFrom<T>>::Error

The type returned in the event of a conversion error.
source§

fn try_into(self) -> Result<U, <U as TryFrom<T>>::Error>

Performs the conversion.
source§

impl<T> WithSubscriber for T

source§

fn with_subscriber<S>(self, subscriber: S) -> WithDispatch<Self>
where S: Into<Dispatch>,

Attaches the provided Subscriber to this type, returning a WithDispatch wrapper. Read more
source§

fn with_current_subscriber(self) -> WithDispatch<Self>

Attaches the current default Subscriber to this type, returning a WithDispatch wrapper. Read more
source§

impl<T> DeserializeOwned for T
where T: for<'de> Deserialize<'de>,

source§

impl<T> RpcObject for T
where T: RpcParam + RpcReturn,

source§

impl<T> RpcParam for T
where T: Serialize + Clone + Debug + Send + Sync + Unpin,

source§

impl<T> RpcReturn for T
where T: DeserializeOwned + Debug + Send + Sync + Unpin + 'static,