vetis 0.1.4-beta.8

Very Tiny Server
//! Error handling types for VeTiS.
//!
//! This module defines the comprehensive error types used throughout
//! the VeTiS server, providing detailed error information for
//! configuration, runtime, and TLS-related issues.
//! ```

use thiserror::Error;

/// Main error type for VeTiS operations.
///
/// This enum encompasses all possible errors that can occur during
/// server configuration, startup, and operation. Each variant provides
/// specific context about what went wrong.
#[derive(Debug, Error, PartialEq)]
pub enum VetisError {
    /// Configuration-related errors
    #[error("Configuration error: {0}")]
    Config(#[from] ConfigError),

    /// Failed to bind to a network address
    #[error("Failed to bind to address: {0}")]
    Bind(String),

    /// Server startup errors
    #[error("Failed to start server: {0}")]
    Start(#[from] StartError),

    /// Server shutdown errors
    #[error("Failed to stop server: {0}")]
    Stop(String),

    /// Request handler errors
    #[error("Handler error: {0}")]
    Handler(String),

    /// TLS/SSL related errors
    #[error("Tls error: {0}")]
    Tls(String),

    /// No server instances are running
    #[error("No instances")]
    NoInstances,

    /// Virtual host related errors
    #[error("Virtual host error: {0}")]
    VirtualHost(#[from] VirtualHostError),
}

/// Configuration-related errors.
///
/// These errors occur during the parsing and validation of
/// server and virtual host configurations.
#[derive(Debug, Clone, Error, PartialEq)]
pub enum ConfigError {
    /// Invalid auth configuration
    #[error("Invalid auth config: {0}")]
    Auth(String),
    /// No listeners configured
    #[error("Invalid server config: {0}")]
    Server(String),
    /// Invalid listener configuration
    #[error("Invalid listener config: {0}")]
    Listener(String),
    /// Invalid virtual host configuration
    #[error("Invalid virtual host config: {0}")]
    VirtualHost(String),
    /// Invalid path configuration
    #[error("Invalid path config: {0}")]
    Path(String),
    /// Invalid security configuration
    #[error("Invalid security config: {0}")]
    Security(String),
}

/// Server startup errors.
///
/// These errors occur when the server fails to start properly,
/// typically due to TLS initialization issues.
#[derive(Debug, Clone, Error, PartialEq)]
pub enum StartError {
    /// TLS/SSL initialization errors
    #[error("Tls initialization: {0}")]
    Tls(String),
}

/// Virtual host related errors.
///
/// These errors occur when working with virtual hosts,
/// such as missing handlers or configuration issues.
#[derive(Debug, Clone, Error, PartialEq)]
pub enum VirtualHostError {
    /// No virtual hosts have been added to the server
    #[error("No virtual hosts")]
    NoVirtualHosts,

    /// Handler errors
    #[error("Handler error: {0}")]
    Handler(HandlerError),

    /// File errors
    #[error("File error: {0}")]
    File(FileError),

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

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

    /// Authentication errors
    #[error("Auth error: {0}")]
    Auth(String),
}

/// Handler related errors.
///
/// These errors occur when working with request handlers,
/// such as URI parsing or handler execution failures.
#[derive(Debug, Clone, Error, PartialEq)]
pub enum HandlerError {
    /// URI parsing errors
    #[error("Uri error: {0}")]
    Uri(String),

    /// Handler execution errors
    #[error("Handler error: {0}")]
    Handler(String),
}

/// File related errors.
///
/// These errors occur when working with files,
/// such as missing files or invalid metadata.
#[derive(Debug, Clone, Error, PartialEq)]
pub enum FileError {
    /// File not found
    #[error("File not found")]
    NotFound,

    /// Invalid file metadata
    #[error("Invalid metadata")]
    InvalidMetadata,

    /// Invalid range
    #[error("Invalid range")]
    InvalidRange,
}