crates/gunnar-bitmap/src/error.rs
//! One error type for the whole crate.
/// Everything that can go wrong reading or writing a `.bitmap`.
#[derive(Debug, thiserror::Error)]
#[non_exhaustive]
pub enum Error {
#[error("expected {wanted} but the input ended")]
/// The input ran out where a field was expected.
UnexpectedEof {
/// What the parser was looking for.
wanted: &'static str,
},
#[error("corrupt ewah bitmap: {reason}")]
/// The compressed stream does not describe a well-formed chunk sequence.
CorruptEwah {
/// Why the stream was rejected.
reason: &'static str,
},
#[error("not a bitmap index: expected the magic {expected:?}, got {actual:?}")]
/// The file does not start with `BITM`.
Magic {
/// Always `BITM`.
expected: &'static [u8; 4],
/// What was there instead.
actual: [u8; 4],
},
#[error("unsupported bitmap index version {actual}, only version 1 exists")]
/// A version other than 1, which is the only one that exists.
Version {
/// The version that was found.
actual: u16,
},
#[error(
"the BITMAP_OPT_FULL_DAG flag (0x1) is required by the format but flags are {flags:#06x}"
)]
/// The mandatory `BITMAP_OPT_FULL_DAG` flag is absent.
MissingFullDag {
/// The flags as read.
flags: u16,
},
#[error(
"bit {bit} was set after bit_size had already reached {bit_size}; \
set_bit needs strictly ascending positions"
)]
/// [`crate::Builder::set_bit`] was given a non-ascending position.
BitsOutOfOrder {
/// The offending position.
bit: u32,
/// How far the builder had already got.
bit_size: u64,
},
#[error("entry {entry} is xor-compressed against entry {entry} - {offset}, which is before the start of the file")]
/// An entry names an XOR base that lies before the first entry.
XorBeforeStart {
/// Index of the entry at fault.
entry: usize,
/// The offset it asked for.
offset: u8,
},
#[error("the trailing bytes are not a whole number of 32-bit name hashes ({tail} bytes left)")]
/// The bytes after the entries are not a whole number of name hashes.
TrailingBytes {
/// How many bytes were left over.
tail: usize,
},
#[error("no bitmap is stored for commit at pack index position {pos}")]
/// The index stores no bitmap for the requested commit.
NoBitmapForCommit {
/// The pack index position asked for.
pos: u32,
},
/// The trailing checksum does not match the file body.
#[error(
"the bitmap's trailing checksum {expected} does not match its contents; \
the file is corrupt or truncated"
)]
ChecksumMismatch {
/// The checksum the file claims.
expected: gix_hash::ObjectId,
},
/// The object count derived from the file disagrees with the pack.
#[error("the bitmap covers {in_bitmap} objects but the pack holds {in_pack}")]
ObjectCountMismatch {
/// Objects the bitmap's name-hash cache accounts for.
in_bitmap: u32,
/// Objects actually in the pack.
in_pack: u32,
},
#[error("io error")]
/// Reading or writing the file failed.
Io(#[from] std::io::Error),
}