Skip to main content

grit_lib/pack_bitmap/
error.rs

1//! Errors while opening or reading pack / MIDX reachability bitmaps.
2
3use thiserror::Error;
4
5/// Failure mode when a `.bitmap` sidecar cannot be used.
6#[derive(Debug, Error, Clone, PartialEq, Eq)]
7#[non_exhaustive]
8pub enum BitmapError {
9    /// The file is empty or shorter than a bitmap header.
10    #[error("bitmap file is too small")]
11    TooSmall,
12    /// The `BITM` signature or version is wrong.
13    #[error("bitmap header is invalid")]
14    InvalidHeader,
15    /// Required `BITMAP_OPT_FULL_DAG` is missing.
16    #[error("bitmap index missing required full-dag flag")]
17    MissingFullDag,
18    /// On-disk trailer hash does not match file contents.
19    #[error("bitmap file checksum mismatch")]
20    FileChecksumMismatch,
21    /// Header pack/MIDX checksum does not match the object database.
22    #[error("bitmap checksum does not match pack or MIDX")]
23    PackChecksumMismatch,
24    /// An extension or entry could not be parsed safely.
25    #[error("bitmap index is corrupt")]
26    Corrupt,
27    /// Embedded EWAH payload is invalid.
28    #[error("bitmap EWAH data is invalid")]
29    InvalidEwah,
30    /// I/O while mapping or reading the bitmap file.
31    #[error("bitmap I/O error: {0}")]
32    Io(String),
33}
34
35impl BitmapError {
36    pub(crate) fn io(err: std::io::Error) -> Self {
37        Self::Io(err.to_string())
38    }
39}