tufazip_prior/error.rs
1use thiserror::Error;
2
3/// Errors returned when reading, writing, or validating quantized prior archives.
4#[derive(Debug, Error)]
5pub enum PriorError {
6 /// Archive header magic is not one of `QPR1`, `QPI1`, `LRA1`, or `QLA1`.
7 #[error("unknown tensor archive magic: {0:?}")]
8 UnknownMagic([u8; 4]),
9
10 /// Archive ended before header, metadata, or tensor payload finished.
11 #[error("truncated tensor archive while reading {0}")]
12 Truncated(String),
13
14 /// Archive metadata version is unsupported.
15 #[error("unsupported tensor archive version {0}")]
16 UnsupportedVersion(u32),
17
18 /// Archive metadata contains invalid tensor descriptors.
19 #[error("invalid archive metadata: {0}")]
20 InvalidMetadata(String),
21
22 /// Archive defines the same tensor name twice.
23 #[error("duplicate archive tensor: {0}")]
24 DuplicateTensor(String),
25
26 /// Tensor shape is empty or contains a zero dimension.
27 #[error("invalid tensor shape for {name}: {shape:?}")]
28 InvalidShape {
29 /// Tensor parameter name.
30 name: String,
31 /// Invalid shape dimensions.
32 shape: Vec<usize>,
33 },
34
35 /// Bit width is not one of `1`, `2`, `4`, `8`, or `16`.
36 #[error("unsupported bit width {bits} for {name}")]
37 UnsupportedBitWidth {
38 /// Tensor parameter name.
39 name: String,
40 /// Unsupported bit width.
41 bits: u8,
42 },
43
44 /// Entry byte count or scale count does not match its shape and bit width.
45 #[error("size mismatch for {name}: {detail}")]
46 SizeMismatch {
47 /// Tensor parameter name.
48 name: String,
49 /// Explanation of the mismatch.
50 detail: String,
51 },
52
53 /// Unexpected data found after the final tensor entry.
54 #[error("tensor archive has trailing bytes")]
55 TrailingBytes,
56
57 /// Prior initialization metadata does not match the target model or vocabulary.
58 #[error("prior validation failed: {0}")]
59 Validation(String),
60
61 /// Underlying I/O error.
62 #[error(transparent)]
63 Io(#[from] std::io::Error),
64
65 /// JSON metadata parsing or serialization error.
66 #[error(transparent)]
67 Json(#[from] serde_json::Error),
68}