cstats-core 0.1.1

Core library for cstats - statistical analysis and metrics collection
Documentation
//! Error types for cstats-core

use std::fmt;

/// Result type alias for cstats operations
pub type Result<T> = std::result::Result<T, Error>;

/// Main error type for cstats operations
#[derive(Debug, thiserror::Error)]
pub enum Error {
    /// Configuration errors
    #[error("Configuration error: {0}")]
    Config(String),

    /// HTTP client errors
    #[error("HTTP request error: {0}")]
    Http(#[from] reqwest::Error),

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

    /// I/O errors
    #[error("I/O error: {0}")]
    Io(#[from] std::io::Error),

    /// Cache operation errors
    #[error("Cache error: {0}")]
    Cache(String),

    /// Statistics calculation errors
    #[error("Statistics error: {0}")]
    Statistics(String),

    /// API errors
    #[error("API error: {0}")]
    Api(String),

    /// Generic errors
    #[error("Error: {0}")]
    Other(#[from] anyhow::Error),
}

impl Error {
    /// Create a new configuration error
    pub fn config<T: fmt::Display>(msg: T) -> Self {
        Self::Config(msg.to_string())
    }

    /// Create a new cache error
    pub fn cache<T: fmt::Display>(msg: T) -> Self {
        Self::Cache(msg.to_string())
    }

    /// Create a new statistics error
    pub fn statistics<T: fmt::Display>(msg: T) -> Self {
        Self::Statistics(msg.to_string())
    }

    /// Create a new API error
    pub fn api<T: fmt::Display>(msg: T) -> Self {
        Self::Api(msg.to_string())
    }
}