Skip to main content

buff_rs/
error.rs

1//! Error types for BUFF encoding/decoding operations.
2
3use thiserror::Error;
4
5/// Errors that can occur during BUFF operations.
6#[derive(Debug, Error, Clone, PartialEq)]
7pub enum BuffError {
8    /// The input data is empty.
9    #[error("input data is empty")]
10    EmptyInput,
11
12    /// Invalid precision value (must be >= 0).
13    #[error("invalid precision: {0} (must be >= 0)")]
14    InvalidPrecision(i32),
15
16    /// The encoded data is corrupted or invalid.
17    #[error("invalid encoded data: {0}")]
18    InvalidData(String),
19
20    /// Buffer overflow during bit packing operations.
21    #[error("buffer overflow: attempted to write {attempted} bits, only {available} available")]
22    BufferOverflow {
23        /// The number of bits that were attempted to be written.
24        attempted: usize,
25        /// The number of bits available in the buffer.
26        available: usize,
27    },
28
29    /// The bit width exceeds the maximum supported (32 bits).
30    #[error("bit width {0} exceeds maximum of 32")]
31    BitWidthExceeded(usize),
32
33    /// Special float values (Infinity, NaN) cannot be converted to decimal.
34    #[error("special float value cannot be converted: {0}")]
35    SpecialValueConversion(String),
36
37    /// Precision loss during decimal conversion exceeds acceptable threshold.
38    #[error("precision loss too high: original={original}, converted={converted}")]
39    PrecisionLoss {
40        /// The original value.
41        original: String,
42        /// The converted value.
43        converted: String,
44    },
45}