Skip to main content

Module errors

Module errors 

Source
Expand description

Error types for the semioscan library.

This module provides strongly-typed errors for all public APIs in semioscan. It follows a hybrid approach:

  • Module-specific errors for fine-grained error handling (BlockWindowError, GasCalculationError, etc.)
  • Unified error type (SemioscanError) for convenience when you don’t need to distinguish between error sources

§Architecture

Each major module has its own error type:

Additionally, RpcError provides shared error variants for blockchain RPC operations.

§Examples

§Fine-grained error handling

use semioscan::{BlockWindowCalculator, BlockWindowError};
use alloy_chains::NamedChain;
use chrono::NaiveDate;

async fn example() -> Result<(), Box<dyn std::error::Error>> {
    let calculator = BlockWindowCalculator::with_disk_cache(provider, "cache.json")?;
    let date = NaiveDate::from_ymd_opt(2024, 1, 15).unwrap();

    match calculator.get_daily_window(NamedChain::Arbitrum, date).await {
        Ok(window) => println!("Block window: {:?}", window),
        Err(BlockWindowError::InvalidRange { reason }) => {
            eprintln!("Invalid range: {}", reason);
        }
        Err(BlockWindowError::Rpc(rpc_err)) => {
            eprintln!("RPC failure, retrying...: {}", rpc_err);
        }
        Err(e) => eprintln!("Other error: {}", e),
    }
    Ok(())
}

§Using the unified error type

use semioscan::{SemioscanError, BlockWindowCalculator};
use alloy_chains::NamedChain;
use chrono::NaiveDate;

async fn example() -> Result<(), SemioscanError> {
    let calculator = BlockWindowCalculator::with_disk_cache(provider, "cache.json")?;
    let date = NaiveDate::from_ymd_opt(2024, 1, 15).unwrap();
    let window = calculator.get_daily_window(NamedChain::Arbitrum, date).await?;
    // Errors automatically convert to SemioscanError via From implementations
    Ok(())
}

Enums§

BlockWindowError
Errors that can occur during block window calculations.
EventProcessingError
Errors that can occur during event processing.
GasCalculationError
Errors that can occur during gas cost calculations.
PriceCalculationError
Errors that can occur during price calculations.
RetrievalError
Errors that can occur during data retrieval operations.
RpcError
Errors that can occur during blockchain RPC operations.
SemioscanError
Unified error type for all semioscan operations.