Skip to main content

Error

Enum Error 

Source
#[non_exhaustive]
pub enum Error { Api { status: u16, message: String, }, RateLimited { message: String, retry_after: Option<Duration>, }, Transport(Error), Decode { message: String, body: String, }, InvalidBaseUrl { url: String, message: String, }, InvalidArgument { message: String, }, ContractRevert { kind: RevertKind, message: String, error_name: Option<String>, selector: Option<String>, data: String, retryable: bool, token_address: Option<String>, }, Rpc { method: String, message: String, code: Option<i64>, data: Option<Value>, }, RpcTransport { method: String, source: Error, }, }
Expand description

Anything that can go wrong talking to the Fyuz API.

The two variants worth matching on explicitly are Error::RateLimited — raised only after the client has exhausted its automatic retries — and Error::Api, which carries the HTTP status and the server’s own message parsed out of the {"error": "..."} envelope.

use fyuz::Error;

fn describe(err: &Error) -> String {
    match err {
        Error::RateLimited { retry_after, .. } => {
            format!("slow down, retry after {:?}", retry_after)
        }
        Error::Api { status: 404, .. } => "no such token".to_string(),
        other => other.to_string(),
    }
}

Variants (Non-exhaustive)§

This enum is marked as non-exhaustive
Non-exhaustive enums could have additional variants added in future. Therefore, when matching against variants of non-exhaustive enums, an extra wildcard arm must be added to account for any future variants.
§

Api

The API answered with a non-2xx status other than 429.

message is the server’s {"error": "..."} text when the body carried one, otherwise a trimmed excerpt of the raw body.

Fields

§status: u16

HTTP status code.

§message: String

Server-supplied message.

§

RateLimited

The API rate limit (120 requests/minute per IP) was hit and the configured number of retries did not clear it.

Fields

§message: String

Server-supplied message, normally "Too many requests".

§retry_after: Option<Duration>

Value of the Retry-After header, when the server sent one.

§

Transport(Error)

The request never produced an HTTP response: DNS failure, connection refused, TLS failure or the configured timeout elapsing.

§

Decode

A 2xx response arrived but did not deserialise into the expected type.

Fields

§message: String

The serde error.

§body: String

First 256 bytes of the body, lossily decoded, to make the mismatch obvious in a log line.

§

InvalidBaseUrl

FyuzClientBuilder::base_url was given something that is not a usable HTTP base URL.

Fields

§url: String

The rejected input.

§message: String

Why it was rejected.

§

InvalidArgument

An argument failed validation before any request was sent.

Raised by the trading layer for a malformed address, an amount that is not a whole number of wei, or a build called without slippage protection.

Fields

§message: String

What was wrong, and usually what to do instead.

§

ContractRevert

The contract rejected a call.

Raised from a simulated eth_call, so it costs nothing — this is the failure you want, rather than paying gas to discover the same thing on-chain. Error::is_graduated picks out the case where the token has left the bonding curve.

Fields

§kind: RevertKind

Classification from shared/test-vectors/trade-errors.json.

§message: String

Human-readable explanation, including what to do about it.

§error_name: Option<String>

Solidity signature, e.g. SlippageExceeded(), when recognised.

§selector: Option<String>

The 4-byte selector, when the revert carried one.

§data: String

Raw revert data, kept so an unrecognised revert is still diagnosable.

§retryable: bool

Whether re-quoting and retrying could plausibly succeed.

§token_address: Option<String>

The token, when this is a graduation refusal.

§

Rpc

A JSON-RPC node returned an error, or something that was not a JSON-RPC response.

Fields

§method: String

The method that failed, e.g. eth_call.

§message: String

The node’s message.

§code: Option<i64>

JSON-RPC error code, when the node sent a well-formed error object.

§data: Option<Value>

The node’s error.data, kept structurally rather than folded into message.

This is where the revert payload lives on most providers, and it is the only place it can be read unambiguously: a node is free to put an address in its prose, and an address is longer than a 4-byte selector, so recovering the selector by scanning text is a guess.

§

RpcTransport

A JSON-RPC request never produced a response.

Distinct from Error::Transport so the failing method is visible: a caller reading http transport error: … cannot tell an unreachable node from an unreachable API. The underlying reqwest::Error is kept, so Error::is_timeout still answers correctly.

Fields

§method: String

The method that failed, e.g. eth_call.

§source: Error

The transport failure underneath.

Implementations§

Source§

impl Error

Source

pub fn status(&self) -> Option<u16>

HTTP status, when the failure came from an HTTP response.

Source

pub fn is_rate_limited(&self) -> bool

Source

pub fn is_not_found(&self) -> bool

true when the API answered 404 — an unknown token, profile or round.

Source

pub fn is_graduated(&self) -> bool

true when a trade was refused because the token left the bonding curve.

The curve is closed once a token graduates, and every swap entrypoint reverts. Trade its DEX pair instead.

Source

pub fn is_retryable_revert(&self) -> bool

true when the contract rejected the call and retrying could plausibly help — a slippage miss or an expired deadline, not a closed curve.

Source

pub fn is_timeout(&self) -> bool

true when the request timed out rather than being answered.

Source

pub fn retry_after(&self) -> Option<Duration>

The server’s Retry-After, when it sent one with a 429.

Trait Implementations§

Source§

impl Debug for Error

Source§

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

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

impl Display for Error

Source§

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

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

impl Error for Error

Source§

fn source(&self) -> Option<&(dyn Error + 'static)>

Returns the lower-level source of this error, if any. Read more
1.0.0 · Source§

fn description(&self) -> &str

👎Deprecated since 1.42.0:

use the Display impl or to_string()

1.0.0 · Source§

fn cause(&self) -> Option<&dyn Error>

👎Deprecated since 1.33.0:

replaced by Error::source, which can support downcasting

Source§

fn provide<'a>(&'a self, request: &mut Request<'a>)

🔬This is a nightly-only experimental API. (error_generic_member_access)
Provides type-based access to context intended for error reports. Read more
Source§

impl From<Error> for Error

Source§

fn from(source: Error) -> Self

Converts to this type from the input type.

Auto Trait Implementations§

§

impl !RefUnwindSafe for Error

§

impl !UnwindSafe for Error

§

impl Freeze for Error

§

impl Send for Error

§

impl Sync for Error

§

impl Unpin for Error

§

impl UnsafeUnpin for Error

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> 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> PolicyExt for T
where T: ?Sized,

Source§

fn and<P, B, E>(self, other: P) -> And<T, P>
where T: Sized + Policy<B, E>, P: Policy<B, E>,

Create a new Policy that returns Action::Follow only if self and other return Action::Follow. Read more
Source§

fn or<P, B, E>(self, other: P) -> Or<T, P>
where T: Sized + Policy<B, E>, P: Policy<B, E>,

Create a new Policy that returns Action::Follow if either self or other returns Action::Follow. Read more
Source§

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

Source§

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 = !

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

fn try_from(value: U) -> Result<T, !>

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