Skip to main content

ahu/
error.rs

1use thiserror::Error;
2
3#[derive(Debug, Error)]
4pub enum AhuError {
5    #[error("invalid magic: expected AHU1, got {found:02x?}")]
6    BadMagic { found: [u8; 4] },
7
8    #[error("unsupported format version {major}.{minor}")]
9    UnsupportedVersion { major: u16, minor: u16 },
10
11    #[error(
12        "header field out of bounds: {field} offset {offset} + length {length} exceeds file size {file_size}"
13    )]
14    HeaderOutOfBounds {
15        field: &'static str,
16        offset: u64,
17        length: u64,
18        file_size: u64,
19    },
20
21    #[error("manifest CBOR decode error: {0}")]
22    ManifestDecode(String),
23
24    #[error("manifest field missing or invalid: {0}")]
25    ManifestField(String),
26
27    #[error("seal validation failed: {0}")]
28    SealInvalid(String),
29
30    #[error("index digest mismatch: expected {expected}, got {actual}")]
31    IndexDigestMismatch { expected: String, actual: String },
32
33    #[error("data digest mismatch: expected {expected}, got {actual}")]
34    DataDigestMismatch { expected: String, actual: String },
35
36    #[error("index not sorted: record {index} key {key} >= next key {next_key}")]
37    IndexNotSorted {
38        index: usize,
39        key: String,
40        next_key: String,
41    },
42
43    #[error("duplicate entry key at index {index}: {key}")]
44    DuplicateEntryKey { index: usize, key: String },
45
46    #[error("index section size {size} is not a multiple of record size {record_size}")]
47    IndexSizeMismatch { size: u64, record_size: usize },
48
49    #[error("epoch rollback: scope {scope} epoch {epoch} <= high-water {high_water}")]
50    EpochRollback {
51        scope: String,
52        epoch: u64,
53        high_water: u64,
54    },
55
56    #[error("continuity break: prev_manifest_digest mismatch for scope {scope}")]
57    ContinuityBreak { scope: String },
58
59    #[error("delta requires base_manifest_digest")]
60    DeltaMissingBase,
61
62    #[error("fork detected: prev_manifest_digest does not match recorded digest for {scope}")]
63    ForkDetected { scope: String },
64
65    #[error("entry at index offset {offset} length {length} exceeds data section")]
66    EntryOutOfBounds { offset: u64, length: u32 },
67
68    #[error("reserved field not zero at index record {index}")]
69    ReservedNotZero { index: usize },
70
71    #[error("I/O error: {0}")]
72    Io(#[from] std::io::Error),
73
74    #[error("bundle write error: {0}")]
75    Write(String),
76
77    #[error("invalid bundle operation: {0}")]
78    InvalidOperation(String),
79}
80
81pub type Result<T> = std::result::Result<T, AhuError>;