1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
//! I/O and serialization errors for `tinyquant-io`.
use thiserror::Error;
/// Errors produced by serialization and file I/O operations.
#[non_exhaustive]
#[derive(Debug, Error)]
pub enum IoError {
/// The input slice is shorter than expected.
#[error("data too short: needed {needed} bytes, got {got}")]
Truncated {
/// Minimum bytes required.
needed: usize,
/// Bytes actually available.
got: usize,
},
/// The format version byte is not recognized.
#[error("unknown format version {got:#04x}")]
UnknownVersion {
/// The version byte found in the data.
got: u8,
},
/// The `bit_width` field in the serialized data is not in `{2, 4, 8}`.
#[error("invalid bit_width {got} in serialized data")]
InvalidBitWidth {
/// The invalid bit-width value.
got: u8,
},
/// The `config_hash` field contains bytes that are not valid UTF-8.
#[error("invalid UTF-8 in config hash")]
InvalidUtf8,
/// A length in the serialized data does not match the expected value.
#[error("input/output length mismatch")]
LengthMismatch,
/// The file magic bytes are not `TQCV`.
#[error("bad magic bytes: expected TQCV, got {got:?}")]
BadMagic {
/// The actual magic bytes found in the file.
got: [u8; 4],
},
/// A header field value is outside its valid range.
#[error("invalid header field")]
InvalidHeader,
/// An inner codec operation failed during decode.
#[error("decode error: {0}")]
Decode(#[from] tinyquant_core::errors::CodecError),
/// A file system I/O error (used in Phase 17+ file-path APIs).
#[error("I/O error: {0}")]
Io(#[from] std::io::Error),
}