Skip to main content

tufazip_preprocess/
error.rs

1use thiserror::Error;
2
3/// Errors returned by dictionary preprocessing, loading, encoding, or decoding.
4#[derive(Debug, Error)]
5pub enum PreprocessError {
6    /// Dictionary file contains an unrecognized backslash escape sequence.
7    #[error("invalid escape sequence in dictionary at byte {0:#04x}")]
8    InvalidEscape(u8),
9
10    /// Dictionary entry exceeds the maximum supported word length (`4096` bytes).
11    #[error("dictionary word exceeds 4096-byte limit")]
12    WordTooLong,
13
14    /// Token stream contains a symbol ID outside the dictionary bounds.
15    #[error("invalid symbol {symbol} for dictionary of size {vocab_size}")]
16    InvalidSymbol {
17        /// Encountered token ID.
18        symbol: u16,
19        /// Number of entries in the dictionary.
20        vocab_size: usize,
21    },
22
23    /// Maximum vocabulary size is invalid (must be at least 256).
24    #[error("max_words ({0}) must be between 256 and 65536")]
25    InvalidMaxWords(usize),
26
27    /// Token stream length is not a multiple of 2 bytes.
28    #[error("preprocessed token stream has odd byte length ({0} bytes)")]
29    OddTokenStreamLength(u64),
30
31    /// Provided dictionary lacks a single-byte entry needed to encode an arbitrary byte.
32    #[error("dictionary is missing single-byte entry for byte {0:#04x}")]
33    MissingByteSymbol(u8),
34
35    /// Underlying I/O error.
36    #[error(transparent)]
37    Io(#[from] std::io::Error),
38}