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:
BlockWindowError- Errors from block window calculationsGasCalculationError- Errors from gas cost calculationsPriceCalculationError- Errors from price calculations (wrapscrate::price::PriceSourceError)EventProcessingError- Errors from event scanning and processingRetrievalError- Errors from combined data retrieval operations
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§
- Block
Window Error - Errors that can occur during block window calculations.
- Event
Processing Error - Errors that can occur during event processing.
- GasCalculation
Error - Errors that can occur during gas cost calculations.
- Price
Calculation Error - Errors that can occur during price calculations.
- Retrieval
Error - Errors that can occur during data retrieval operations.
- RpcError
- Errors that can occur during blockchain RPC operations.
- Semioscan
Error - Unified error type for all semioscan operations.