luff 0.2.1

Print files with formatting
Documentation
//! Error types for the WASM module.
//!
//! These are intentionally slim — no `miette` or rich terminal rendering,
//! since those depend on `std` I/O features unavailable in WASM.

use std::fmt;

/// Errors that can occur during WASM-based processing.
///
/// This enum is `#[non_exhaustive]` — new variants may be added in
/// future minor releases without a semver bump.
///
/// All variants are `Clone` so that errors can be propagated across
/// component boundaries (e.g. serialized via WIT or `serde-wasm-bindgen`)
/// without requiring ownership transfer.
#[derive(Clone, Debug, PartialEq, Eq, thiserror::Error)]
#[non_exhaustive]
pub enum WasmError {
    /// A virtual file path failed validation.
    #[error("invalid path: {0}")]
    InvalidPath(String),

    /// A glob or extension pattern could not be compiled.
    #[error("pattern error: {0}")]
    PatternError(String),

    /// The formatted output exceeded the configured size limit.
    #[error("output too large: {size} bytes exceeds {max} byte limit")]
    OutputTooLarge {
        /// Actual output size in bytes.
        size: usize,
        /// Configured maximum in bytes.
        max: usize,
    },

    /// A formatting write operation failed.
    #[error("formatting error: {0}")]
    Fmt(#[from] fmt::Error),

    /// General processing error.
    #[error("processing error: {0}")]
    Processing(String),
}

impl From<globset::Error> for WasmError {
    fn from(err: globset::Error) -> Self {
        Self::PatternError(err.to_string())
    }
}