PriceSourceError

Enum PriceSourceError 

Source
pub enum PriceSourceError {
    DecodeError(Error),
    EmptyTokenArrays,
    ArrayLengthMismatch {
        tokens_in: usize,
        amounts_in: usize,
        tokens_out: usize,
        amounts_out: usize,
    },
    InvalidSwapData {
        details: String,
    },
}
Expand description

Errors that can occur when extracting price data from logs.

This error type preserves the original error information without type erasure, allowing callers to inspect and handle specific error cases.

§Examples

use semioscan::price::{PriceSource, PriceSourceError};
use alloy_rpc_types::Log;
use alloy_sol_types::SolEvent;

fn extract_swap_from_log(&self, log: &Log) -> Result<Option<SwapData>, PriceSourceError> {
    let event = SwapEvent::decode_log(&log.into())
        .map_err(PriceSourceError::from)?;  // Preserves alloy_sol_types::Error

    if event.amounts.is_empty() {
        return Err(PriceSourceError::empty_token_arrays());
    }

    // ... rest of extraction logic
}

Variants§

§

DecodeError(Error)

Failed to decode an event from the log data.

This preserves the original alloy_sol_types::Error without type erasure, allowing inspection of decode failures (wrong signature, corrupted data, etc.).

§

EmptyTokenArrays

Event was decoded but contains empty token arrays.

SwapMulti events must have at least one token in both tokensIn and tokensOut.

§

ArrayLengthMismatch

Token and amount arrays have mismatched lengths.

SwapMulti events require tokensIn.len() == amountsIn.len() and tokensOut.len() == amountsOut.len().

Fields

§tokens_in: usize

Length of tokensIn array

§amounts_in: usize

Length of amountsIn array

§tokens_out: usize

Length of tokensOut array

§amounts_out: usize

Length of amountsOut array

§

InvalidSwapData

Event was decoded but the swap data is invalid.

This is a catch-all for validation errors beyond the specific cases above, such as zero amounts, invalid token addresses, or other business logic violations.

Unlike the old string-based version, this stores the error in a Box<dyn Error> to preserve the source error chain and enable programmatic error handling.

Fields

§details: String

Description of what makes the swap data invalid

Implementations§

Source§

impl PriceSourceError

Source

pub fn empty_token_arrays() -> Self

Create an EmptyTokenArrays error.

Use this when a SwapMulti event has empty tokensIn or tokensOut arrays.

Source

pub fn array_length_mismatch( tokens_in: usize, amounts_in: usize, tokens_out: usize, amounts_out: usize, ) -> Self

Create an ArrayLengthMismatch error with specific lengths.

Use this when token and amount array lengths don’t match in SwapMulti events.

§Examples
use semioscan::PriceSourceError;

let err = PriceSourceError::array_length_mismatch(2, 3, 1, 1);
assert!(err.to_string().contains("don't match"));
Source

pub fn invalid_swap_data(details: impl Into<String>) -> Self

Create an InvalidSwapData error with details.

Use this for validation errors that don’t fit the more specific error types.

§Examples
use semioscan::PriceSourceError;

let err = PriceSourceError::invalid_swap_data("Zero amount in swap");
assert!(err.to_string().contains("Invalid swap data"));

Trait Implementations§

Source§

impl Debug for PriceSourceError

Source§

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

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

impl Display for PriceSourceError

Source§

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

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

impl Error for PriceSourceError

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 PriceSourceError

Source§

fn from(error: Error) -> Self

Converts to this type from the input type.
Source§

impl From<PriceSourceError> for PriceCalculationError

Source§

fn from(source: PriceSourceError) -> Self

Converts to this type from the input type.

Auto Trait Implementations§

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> IntoEither for T

Source§

fn into_either(self, into_left: bool) -> Either<Self, Self>

Converts self into a Left variant of Either<Self, Self> if into_left is true. Converts self into a Right variant of Either<Self, Self> otherwise. Read more
Source§

fn into_either_with<F>(self, into_left: F) -> Either<Self, Self>
where F: FnOnce(&Self) -> bool,

Converts self into a Left variant of Either<Self, Self> if into_left(&self) returns true. Converts self into a Right variant of Either<Self, Self> otherwise. Read more
Source§

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

Source§

fn and<P, B, E>(self, other: P) -> And<T, P>
where T: 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: 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> Same for T

Source§

type Output = T

Should always be Self
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> ToStringFallible for T
where T: Display,

Source§

fn try_to_string(&self) -> Result<String, TryReserveError>

ToString::to_string, but without panic on OOM.

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<V, T> VZip<V> for T
where V: MultiLane<T>,

Source§

fn vzip(self) -> V

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