qualia_core_db/bundle/stream/index/
error.rs1use crate::bundle::BundleError;
3
4#[derive(Clone, Copy, Debug, PartialEq, Eq)]
5pub enum IndexError {
6 HeaderLength,
7 BadMagic,
8 UnsupportedVersion(u16),
9 Flags,
10 Reserved,
11 Extent,
12 ExtentLimit,
13 Overflow,
14 Footer,
15 Alignment,
16 EncodedLimit,
17 Count,
18 ResidentLimit,
19 Malformed,
20 Field,
21 DuplicateField,
22 MissingField,
23 Text,
24 Digest,
25 EntryBounds,
26 DuplicateKey,
27 Overlap,
28 Scratch,
29 Allocation,
30}
31
32impl IndexError {
33 pub(crate) fn into_bundle_error(self) -> BundleError {
34 match self {
35 Self::HeaderLength => BundleError::TooShort,
36 Self::BadMagic => BundleError::BadMagic,
37 Self::UnsupportedVersion(v) => BundleError::UnsupportedVersion(v),
38 _ => BundleError::Cbor(self.message().into()),
39 }
40 }
41
42 pub const fn message(self) -> &'static str {
43 match self {
44 Self::HeaderLength => "QBDL header must be exactly 64 bytes",
45 Self::BadMagic => "QBDL magic differs",
46 Self::UnsupportedVersion(_) => "QBDL version unsupported",
47 Self::Flags => "QBDL flags unsupported",
48 Self::Reserved => "QBDL reserved header bytes are nonzero",
49 Self::Extent => "QBDL logical extent differs",
50 Self::ExtentLimit => "QBDL logical extent exceeds limit",
51 Self::Overflow => "QBDL arithmetic overflow",
52 Self::Footer => "QBDL index is not the exact footer",
53 Self::Alignment => "QBDL alignment differs",
54 Self::EncodedLimit => "QBDL index exceeds encoded limit",
55 Self::Count => "QBDL entry count differs or exceeds limit",
56 Self::ResidentLimit => "QBDL index exceeds aggregate resident reservation",
57 Self::Malformed => "QBDL index encoding is malformed or unsupported",
58 Self::Field => "QBDL index field is unknown or invalid",
59 Self::DuplicateField => "QBDL index field occurs twice",
60 Self::MissingField => "QBDL index required field is missing",
61 Self::Text => "QBDL index text is empty or exceeds limit",
62 Self::Digest => "QBDL entry requires exactly 32 digest bytes",
63 Self::EntryBounds => "QBDL entry exceeds payload bounds",
64 Self::DuplicateKey => "QBDL entry key occurs twice",
65 Self::Overlap => "QBDL nonempty payload ranges overlap",
66 Self::Scratch => "QBDL caller scratch is insufficient",
67 Self::Allocation => "QBDL cold index allocation unavailable",
68 }
69 }
70}
71
72impl core::fmt::Display for IndexError {
73 fn fmt(&self, f: &mut core::fmt::Formatter<'_>) -> core::fmt::Result {
74 f.write_str(self.message())
75 }
76}
77impl std::error::Error for IndexError {}