Skip to main content

rocketsplash_formats/
error.rs

1// <FILE>crates/rocketsplash-formats/src/error.rs</FILE>
2// <DESC>Typed validation and decode errors for serialized formats</DESC>
3// <VERS>VERSION: 1.0.0</VERS>
4// <WCTX>Foundation crates 0.3.0 (RELEASE_PLAN D2 typed errors)</WCTX>
5// <CLOG>1.0.0: introduce FormatError, replacing stringly-typed Result<_, String> across the crate.</CLOG>
6
7use thiserror::Error;
8
9/// Typed error for format validation and decoding.
10///
11/// Every fallible public API in this crate returns `FormatError`; consumers
12/// can match on variants instead of parsing message strings (RELEASE_PLAN D2).
13#[derive(Debug, Clone, PartialEq, Eq, Error)]
14pub enum FormatError {
15    #[error("width {width} exceeds maximum {max}")]
16    WidthExceeded { width: u32, max: u32 },
17
18    #[error("height {height} exceeds maximum {max}")]
19    HeightExceeded { height: u32, max: u32 },
20
21    #[error("dimensions {width}x{height} overflow")]
22    DimensionOverflow { width: u32, height: u32 },
23
24    #[error("cell count {actual} does not match {width}x{height} (expected {expected})")]
25    CellCountMismatch {
26        actual: usize,
27        expected: usize,
28        width: u32,
29        height: u32,
30    },
31
32    #[error("animation frame {frame} has {actual} cells, expected {expected}")]
33    FrameCellCountMismatch {
34        frame: usize,
35        actual: usize,
36        expected: usize,
37    },
38
39    #[error("animation has {count} frames, exceeds maximum {max}")]
40    FrameCountExceeded { count: usize, max: usize },
41
42    #[error("glyph char count {actual} does not match {width}x{height} (expected {expected})")]
43    GlyphCharCountMismatch {
44        actual: usize,
45        expected: usize,
46        width: u32,
47        height: u32,
48    },
49
50    #[error("glyph opacity length {actual} does not match {width}x{height} (expected {expected})")]
51    GlyphOpacityMismatch {
52        actual: usize,
53        expected: usize,
54        width: u32,
55        height: u32,
56    },
57
58    #[error("font atlas has {count} glyphs, exceeds maximum {max}")]
59    GlyphCountExceeded { count: usize, max: usize },
60
61    #[error("font line height must be non-zero")]
62    ZeroLineHeight,
63
64    #[error("allocation size overflow")]
65    AllocationOverflow,
66
67    #[error("total allocation {requested} exceeds limit {limit} bytes")]
68    AllocationExceeded { requested: usize, limit: usize },
69
70    #[error("serialized payload of {len} bytes exceeds limit {max}")]
71    PayloadTooLarge { len: usize, max: usize },
72
73    #[error("unsupported {format} version {found}; supported {min_supported}..={current}")]
74    UnsupportedVersion {
75        format: &'static str,
76        found: u8,
77        min_supported: u8,
78        current: u8,
79    },
80
81    /// Underlying MessagePack decode failure (truncated/corrupt input).
82    /// Carries the codec's message; the codec error type itself is not `Clone`.
83    #[error("decode error: {0}")]
84    Decode(String),
85}
86
87// <FILE>crates/rocketsplash-formats/src/error.rs</FILE>
88// <VERS>END OF VERSION: 1.0.0</VERS>