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    /// CDX compressed block is corrupted (decompression or decode failure).
39    #[error("cdx block corrupted")]
40    CdxBlockCorrupted,
41
42    /// Section offset exceeds the index file bounds.
43    /// Section offset exceeds the index file bounds.
44    #[error("section offset out of bounds: {section} at {offset}+{size} > {file_len}")]
45    SectionOutOfBounds {
46        /// Name of the section being accessed.
47        section: &'static str,
48        /// Byte offset of the section.
49        offset: u64,
50        /// Size of the section in bytes.
51        size: u64,
52        /// Total length of the index file.
53        file_len: u64,
54    },
55
56    /// Truncated varint at the given byte position.
57    #[error("truncated varint at position {0}")]
58    TruncatedVarint(usize),
59
60    /// Varint overflow (exceeds 10 bytes for u64).
61    #[error("varint overflow (> 10 bytes)")]
62    OverflowVarint,
63
64    /// Posting list data extends beyond available buffer.
65    #[error("posting list out of bounds")]
66    PostingOutOfBounds,
67
68    /// File ID exceeds the known file table range.
69    #[error("file_id {0} out of bounds")]
70    FileIdOutOfBounds(u32),
71
72    /// String pool offset out of bounds.
73    #[error("string pool offset out of bounds")]
74    StringPoolOutOfBounds,
75
76    /// Invalid UTF-8 in a stored path.
77    #[error("invalid UTF-8 in path")]
78    InvalidPath,
79
80    /// Regex compilation or matching error.
81    #[error("regex: {0}")]
82    Regex(#[from] regex::Error),
83
84    /// File system watcher error (notify feature).
85    #[cfg(feature = "notify")]
86    #[error("Watcher error: {0}")]
87    Watcher(#[from] notify::Error),
88
89    /// Zip archive error (archive feature).
90    #[cfg(feature = "archive")]
91    #[error("Zip error: {0}")]
92    Zip(#[from] zip::result::ZipError),
93
94    /// Configuration error.
95    #[error("config: {0}")]
96    Config(String),
97}
98
99/// Convenience type alias for `Result<T, Error>`.
100pub type Result<T> = std::result::Result<T, Error>;