Skip to main content

ix/
error.rs

1/// All ix error types.
2#[derive(Debug, thiserror::Error)]
3pub enum Error {
4    /// I/O error.
5    #[error("I/O: {0}")]
6    Io(#[from] std::io::Error),
7
8    /// Index file is too small (< 256 bytes).
9    #[error("index too small (< 256 bytes)")]
10    IndexTooSmall,
11
12    /// Magic bytes mismatch (expected IX01).
13    #[error("bad magic (expected IX01)")]
14    BadMagic,
15
16    /// Unsupported index file version.
17    #[error("unsupported version {major}.{minor}")]
18    UnsupportedVersion {
19        /// Major version number.
20        major: u16,
21        /// Minor version number.
22        minor: u16,
23    },
24
25    /// Header CRC checksum mismatch.
26    #[error("header CRC mismatch (expected {expected:#010x}, got {actual:#010x})")]
27    HeaderCorrupted {
28        /// Expected CRC value.
29        expected: u32,
30        /// Actual CRC value found.
31        actual: u32,
32    },
33
34    /// Posting list data is corrupted (CRC mismatch).
35    #[error("posting list corrupted (CRC mismatch)")]
36    PostingCorrupted,
37
38    /// Section offset exceeds the index file bounds.
39    #[error("section offset out of bounds: {section} at {offset}+{size} > {file_len}")]
40    SectionOutOfBounds {
41        /// Name of the section being accessed.
42        section: &'static str,
43        /// Byte offset of the section.
44        offset: u64,
45        /// Size of the section in bytes.
46        size: u64,
47        /// Total length of the index file.
48        file_len: u64,
49    },
50
51    /// Truncated varint at the given byte position.
52    #[error("truncated varint at position {0}")]
53    TruncatedVarint(usize),
54
55    /// Varint overflow (exceeds 10 bytes for u64).
56    #[error("varint overflow (> 10 bytes)")]
57    OverflowVarint,
58
59    /// Posting list data extends beyond available buffer.
60    #[error("posting list out of bounds")]
61    PostingOutOfBounds,
62
63    /// File ID exceeds the known file table range.
64    #[error("file_id {0} out of bounds")]
65    FileIdOutOfBounds(u32),
66
67    /// String pool offset out of bounds.
68    #[error("string pool offset out of bounds")]
69    StringPoolOutOfBounds,
70
71    /// Invalid UTF-8 in a stored path.
72    #[error("invalid UTF-8 in path")]
73    InvalidPath,
74
75    /// Regex compilation or matching error.
76    #[error("regex: {0}")]
77    Regex(#[from] regex::Error),
78
79    /// File system watcher error (notify feature).
80    #[cfg(feature = "notify")]
81    #[error("Watcher error: {0}")]
82    Watcher(#[from] notify::Error),
83
84    /// Zip archive error (archive feature).
85    #[cfg(feature = "archive")]
86    #[error("Zip error: {0}")]
87    Zip(#[from] zip::result::ZipError),
88
89    /// Configuration error.
90    #[error("config: {0}")]
91    Config(String),
92}
93
94/// Convenience type alias for `Result<T, Error>`.
95pub type Result<T> = std::result::Result<T, Error>;