Skip to main content

uni_sparse_vector/
error.rs

1use thiserror::Error;
2
3/// Errors produced by `SparseVector` construction, encoding, and decoding.
4#[derive(Debug, Error, Clone, PartialEq)]
5pub enum SparseError {
6    /// `indices` and `values` had different lengths.
7    #[error("SV-1: indices ({indices}) and values ({values}) must have equal length")]
8    LengthMismatch { indices: usize, values: usize },
9
10    /// `indices` were not in strictly ascending order (which also forbids duplicates).
11    #[error(
12        "SV-2: indices must be strictly ascending (sorted + unique); violation at position {position} ({prev} >= {curr})"
13    )]
14    UnsortedIndices {
15        position: usize,
16        prev: u32,
17        curr: u32,
18    },
19
20    /// A weight was non-finite (NaN or ±infinity).
21    #[error("SV-3: weight at position {position} is non-finite ({value})")]
22    NonFiniteWeight { position: usize, value: f32 },
23
24    /// An encoded buffer was too short to contain its declared payload.
25    #[error("SV-4: encoded buffer truncated: need {need} bytes, got {got}")]
26    Truncated { need: usize, got: usize },
27
28    /// An encoded buffer carried trailing bytes after its declared payload.
29    #[error("SV-5: encoded buffer has {trailing} unexpected trailing byte(s)")]
30    TrailingBytes { trailing: usize },
31}