rocketsplash-formats 0.3.0

Shared data types and serialization formats for Rocketsplash TUI animations
Documentation
// <FILE>crates/rocketsplash-formats/src/error.rs</FILE>
// <DESC>Typed validation and decode errors for serialized formats</DESC>
// <VERS>VERSION: 1.0.0</VERS>
// <WCTX>Foundation crates 0.3.0 (RELEASE_PLAN D2 typed errors)</WCTX>
// <CLOG>1.0.0: introduce FormatError, replacing stringly-typed Result<_, String> across the crate.</CLOG>

use thiserror::Error;

/// Typed error for format validation and decoding.
///
/// Every fallible public API in this crate returns `FormatError`; consumers
/// can match on variants instead of parsing message strings (RELEASE_PLAN D2).
#[derive(Debug, Clone, PartialEq, Eq, Error)]
pub enum FormatError {
    #[error("width {width} exceeds maximum {max}")]
    WidthExceeded { width: u32, max: u32 },

    #[error("height {height} exceeds maximum {max}")]
    HeightExceeded { height: u32, max: u32 },

    #[error("dimensions {width}x{height} overflow")]
    DimensionOverflow { width: u32, height: u32 },

    #[error("cell count {actual} does not match {width}x{height} (expected {expected})")]
    CellCountMismatch {
        actual: usize,
        expected: usize,
        width: u32,
        height: u32,
    },

    #[error("animation frame {frame} has {actual} cells, expected {expected}")]
    FrameCellCountMismatch {
        frame: usize,
        actual: usize,
        expected: usize,
    },

    #[error("animation has {count} frames, exceeds maximum {max}")]
    FrameCountExceeded { count: usize, max: usize },

    #[error("glyph char count {actual} does not match {width}x{height} (expected {expected})")]
    GlyphCharCountMismatch {
        actual: usize,
        expected: usize,
        width: u32,
        height: u32,
    },

    #[error("glyph opacity length {actual} does not match {width}x{height} (expected {expected})")]
    GlyphOpacityMismatch {
        actual: usize,
        expected: usize,
        width: u32,
        height: u32,
    },

    #[error("font atlas has {count} glyphs, exceeds maximum {max}")]
    GlyphCountExceeded { count: usize, max: usize },

    #[error("font line height must be non-zero")]
    ZeroLineHeight,

    #[error("allocation size overflow")]
    AllocationOverflow,

    #[error("total allocation {requested} exceeds limit {limit} bytes")]
    AllocationExceeded { requested: usize, limit: usize },

    #[error("serialized payload of {len} bytes exceeds limit {max}")]
    PayloadTooLarge { len: usize, max: usize },

    #[error("unsupported {format} version {found}; supported {min_supported}..={current}")]
    UnsupportedVersion {
        format: &'static str,
        found: u8,
        min_supported: u8,
        current: u8,
    },

    /// Underlying MessagePack decode failure (truncated/corrupt input).
    /// Carries the codec's message; the codec error type itself is not `Clone`.
    #[error("decode error: {0}")]
    Decode(String),
}

// <FILE>crates/rocketsplash-formats/src/error.rs</FILE>
// <VERS>END OF VERSION: 1.0.0</VERS>