1use thiserror::Error;
4
5#[derive(Debug, Error)]
7pub enum CrousError {
8 #[error("I/O error: {0}")]
9 Io(#[from] std::io::Error),
10
11 #[error("Invalid magic bytes in file header: expected CROUSv1")]
12 InvalidMagic,
13
14 #[error("Unsupported format version: {0}")]
15 UnsupportedVersion(u8),
16
17 #[error("Invalid wire type tag: 0x{0:02x}")]
18 InvalidWireType(u8),
19
20 #[error("Varint overflow: encoded integer exceeds 64 bits")]
21 VarintOverflow,
22
23 #[error("Unexpected end of input at offset {0}")]
24 UnexpectedEof(usize),
25
26 #[error("Checksum mismatch: expected 0x{expected:016x}, got 0x{actual:016x}")]
27 ChecksumMismatch { expected: u64, actual: u64 },
28
29 #[error("Invalid UTF-8 in string field at offset {0}")]
30 InvalidUtf8(usize),
31
32 #[error("Nesting depth {0} exceeds maximum {1}")]
33 NestingTooDeep(usize, usize),
34
35 #[error("Block size {0} exceeds maximum {1}")]
36 BlockTooLarge(usize, usize),
37
38 #[error("Item count {0} exceeds maximum {1}")]
39 TooManyItems(usize, usize),
40
41 #[error("Unknown compression type: {0}")]
42 UnknownCompression(u8),
43
44 #[error("Decompression error: {0}")]
45 DecompressionError(String),
46
47 #[error("Invalid block type: {0}")]
48 InvalidBlockType(u8),
49
50 #[error("Text parse error at line {line}, col {col}: {message}")]
51 ParseError {
52 line: usize,
53 col: usize,
54 message: String,
55 },
56
57 #[error("Schema mismatch: {0}")]
58 SchemaMismatch(String),
59
60 #[error("Memory limit exceeded: requested {0} bytes, limit {1}")]
61 MemoryLimitExceeded(usize, usize),
62
63 #[error("Invalid base64 data: {0}")]
64 InvalidBase64(String),
65
66 #[error("Invalid data: {0}")]
67 InvalidData(String),
68}
69
70pub type Result<T> = std::result::Result<T, CrousError>;