eth-etl-core 0.1.0

Core types and utilities for Ethereum ETL
Documentation
use thiserror::Error;

#[derive(Error, Debug)]
pub enum EthEtlError {
    #[error("RPC error: {0}")]
    Rpc(#[from] RpcError),

    #[error("Parse error: {0}")]
    Parse(String),

    #[error("IO error: {0}")]
    Io(#[from] std::io::Error),

    #[error("CSV error: {0}")]
    Csv(String),

    #[error("JSON error: {0}")]
    Json(#[from] serde_json::Error),

    #[error("Retriable error (will retry): {0}")]
    Retriable(String),

    #[error("Validation error: {0}")]
    Validation(String),

    #[error("Configuration error: {0}")]
    Config(String),

    #[error("Export error: {0}")]
    Export(String),

    #[error("Provider error: {0}")]
    Provider(String),
}

#[derive(Error, Debug)]
pub enum RpcError {
    #[error("HTTP error: {0}")]
    Http(String),

    #[error("JSON-RPC error code {code}: {message}")]
    JsonRpc { code: i32, message: String },

    #[error("Timeout")]
    Timeout,

    #[error("Connection error: {0}")]
    Connection(String),

    #[error("IPC error: {0}")]
    Ipc(String),
}

impl RpcError {
    /// Check if this error is retriable based on JSON-RPC error codes
    /// Retriable: -32603 (Internal error) or -32000 to -32099 (Server errors)
    pub fn is_retriable(&self) -> bool {
        match self {
            RpcError::JsonRpc { code, .. } => {
                *code == -32603 || (-32099..=-32000).contains(code)
            }
            RpcError::Timeout | RpcError::Connection(_) => true,
            _ => false,
        }
    }
}

pub type Result<T> = std::result::Result<T, EthEtlError>;