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
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.
Implementations§
Source§impl PriceSourceError
impl PriceSourceError
Sourcepub fn empty_token_arrays() -> Self
pub fn empty_token_arrays() -> Self
Create an EmptyTokenArrays error.
Use this when a SwapMulti event has empty tokensIn or tokensOut arrays.
Sourcepub fn array_length_mismatch(
tokens_in: usize,
amounts_in: usize,
tokens_out: usize,
amounts_out: usize,
) -> Self
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"));Sourcepub fn invalid_swap_data(details: impl Into<String>) -> Self
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
impl Debug for PriceSourceError
Source§impl Display for PriceSourceError
impl Display for PriceSourceError
Source§impl Error for PriceSourceError
impl Error for PriceSourceError
Source§fn source(&self) -> Option<&(dyn Error + 'static)>
fn source(&self) -> Option<&(dyn Error + 'static)>
1.0.0 · Source§fn description(&self) -> &str
fn description(&self) -> &str
Source§impl From<Error> for PriceSourceError
impl From<Error> for PriceSourceError
Source§impl From<PriceSourceError> for PriceCalculationError
impl From<PriceSourceError> for PriceCalculationError
Source§fn from(source: PriceSourceError) -> Self
fn from(source: PriceSourceError) -> Self
Auto Trait Implementations§
impl Freeze for PriceSourceError
impl RefUnwindSafe for PriceSourceError
impl Send for PriceSourceError
impl Sync for PriceSourceError
impl Unpin for PriceSourceError
impl UnwindSafe for PriceSourceError
Blanket Implementations§
Source§impl<T> BorrowMut<T> for Twhere
T: ?Sized,
impl<T> BorrowMut<T> for Twhere
T: ?Sized,
Source§fn borrow_mut(&mut self) -> &mut T
fn borrow_mut(&mut self) -> &mut T
Source§impl<T> Instrument for T
impl<T> Instrument for T
Source§fn instrument(self, span: Span) -> Instrumented<Self>
fn instrument(self, span: Span) -> Instrumented<Self>
Source§fn in_current_span(self) -> Instrumented<Self>
fn in_current_span(self) -> Instrumented<Self>
Source§impl<T> IntoEither for T
impl<T> IntoEither for T
Source§fn into_either(self, into_left: bool) -> Either<Self, Self>
fn into_either(self, into_left: bool) -> Either<Self, Self>
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 moreSource§fn into_either_with<F>(self, into_left: F) -> Either<Self, Self>
fn into_either_with<F>(self, into_left: F) -> Either<Self, Self>
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 moreSource§impl<T> PolicyExt for Twhere
T: ?Sized,
impl<T> PolicyExt for Twhere
T: ?Sized,
Source§impl<T> ToStringFallible for Twhere
T: Display,
impl<T> ToStringFallible for Twhere
T: Display,
Source§fn try_to_string(&self) -> Result<String, TryReserveError>
fn try_to_string(&self) -> Result<String, TryReserveError>
ToString::to_string, but without panic on OOM.