slave-framework 0.1.0

Runtime for slave apps: Axum server lifecycle, config, logging, Turso database, migrations and password/token auth
use std::io;
#[cfg(feature = "database")]
use std::path::PathBuf;

/// Errors raised by the slave runtime.
#[derive(Debug, thiserror::Error)]
pub enum Error {
    #[error("failed to load .env file: {0}")]
    Dotenv(#[from] dotenvy::Error),

    #[error("invalid value {value:?} for environment variable {key}: {reason}")]
    InvalidEnv {
        key: String,
        value: String,
        reason: String,
    },

    #[error("failed to initialize logging: {0}")]
    Logging(String),

    #[error("failed to bind to {addr}: {source}")]
    Bind {
        addr: String,
        #[source]
        source: io::Error,
    },

    #[error("server error: {0}")]
    Server(#[source] io::Error),

    #[cfg(feature = "auth")]
    #[error("{0}")]
    Auth(String),

    #[cfg(feature = "database")]
    #[error("database error: {0}")]
    Database(#[from] turso::Error),

    #[cfg(feature = "database")]
    #[error("failed to create database directory {}: {source}", path.display())]
    DatabaseDirectory {
        path: PathBuf,
        #[source]
        source: io::Error,
    },

    #[cfg(feature = "database")]
    #[error("statement {index} failed: {source}")]
    Statement {
        index: usize,
        #[source]
        source: turso::Error,
    },

    #[cfg(feature = "database")]
    #[error("migration `{0}` is registered more than once")]
    DuplicateMigration(String),

    #[cfg(feature = "database")]
    #[error("cannot roll back batch {batch}: {reason}")]
    RollbackRefused { batch: i64, reason: String },
}

/// Shorthand for results returned by the slave runtime.
pub type Result<T, E = Error> = std::result::Result<T, E>;