use std::io;

/// Errors that can occur in the senl framework.
///
/// Library code propagates these via [`Result`]; only the CLI binary
/// should format and print them to stderr/stdout.
#[derive(Debug, thiserror::Error)]
#[non_exhaustive]
pub enum SenlError {
    /// Lua runtime error (eval, type mismatch, require failure, etc.).
    #[error("{0}")]
    Lua(#[from] mlua::Error),

    /// CLI parsing error (missing arg, unknown flag, help/version request).
    ///
    /// The inner [`clap::Error`] knows which stream to print to
    /// and what exit code to use — call `.exit()` or `.print()` in the binary.
    #[error("{0}")]
    Cli(#[from] clap::Error),

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

    /// Application-level error (bad config, missing entry point, etc.).
    #[error("{0}")]
    App(String),
}

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