o402 0.1.2

OpenAI-compatible gateway, paid with x402.
//! Process-level errors (config, init, bind, serve).

use std::net::SocketAddr;
use std::path::PathBuf;

use crate::config::ConfigError;

/// Failure of the `o402` process.
#[derive(Debug, thiserror::Error)]
pub enum AppError {
    /// Configuration could not be loaded or was invalid.
    #[error(transparent)]
    Config(#[from] ConfigError),
    /// `o402 init` refused to overwrite an existing file.
    #[error("'{}' already exists", path.display())]
    AlreadyExists {
        /// Path that already exists.
        path: PathBuf,
    },
    /// `o402 init` could not write the example file.
    #[error("failed to write '{}': {source}", path.display())]
    Write {
        /// Path that could not be written.
        path: PathBuf,
        /// Underlying IO error.
        #[source]
        source: std::io::Error,
    },
    /// TCP bind failed.
    #[error("failed to bind {addr}: {source}")]
    Bind {
        /// Address passed to `TcpListener::bind`.
        addr: SocketAddr,
        /// Underlying IO error.
        #[source]
        source: std::io::Error,
    },
    /// The HTTP server returned an IO error.
    #[error("server: {source}")]
    Server {
        /// Underlying IO error.
        #[source]
        source: std::io::Error,
    },
    /// A `.env` file existed but could not be parsed or read.
    #[error("failed to load .env: {source}")]
    Dotenv {
        /// Underlying dotenvy error.
        #[source]
        source: dotenvy::Error,
    },
    /// An upstream HTTP client could not be constructed.
    #[error("failed to build HTTP client for upstream '{name}': {source}")]
    HttpClient {
        /// `[[upstreams]]` name.
        name: String,
        /// Underlying reqwest error.
        #[source]
        source: reqwest::Error,
    },
    /// Prometheus recorder could not be installed.
    #[error("metrics recorder: {0}")]
    Metrics(String),
}