Skip to main content

kimberlite_store/
error.rs

1//! Error types for store operations.
2
3use std::io;
4
5use crate::Key;
6use crate::types::{PageId, TableId};
7
8/// Errors that can occur during store operations.
9#[derive(thiserror::Error, Debug)]
10pub enum StoreError {
11    /// Filesystem I/O error.
12    #[error("filesystem error: {0}")]
13    Io(#[from] io::Error),
14
15    /// Page CRC32 checksum mismatch - data corruption detected.
16    #[error(
17        "page {page_id} corrupted: CRC mismatch (expected {expected:#010x}, got {actual:#010x})"
18    )]
19    PageCorrupted {
20        page_id: PageId,
21        expected: u32,
22        actual: u32,
23    },
24
25    /// Key exceeds maximum allowed length.
26    #[error("key too long: {len} bytes exceeds maximum {max}")]
27    KeyTooLong { len: usize, max: usize },
28
29    /// Value exceeds maximum size that fits in a page.
30    #[error("value too large: {len} bytes exceeds maximum {max}")]
31    ValueTooLarge { len: usize, max: usize },
32
33    /// Page has invalid magic bytes.
34    #[error("invalid page magic: expected {expected:#010x}, got {actual:#010x}")]
35    InvalidPageMagic { expected: u32, actual: u32 },
36
37    /// Page has unsupported version.
38    #[error("unsupported page version: {0}")]
39    UnsupportedPageVersion(u8),
40
41    /// Superblock has invalid magic bytes.
42    #[error("invalid superblock magic")]
43    InvalidSuperblockMagic,
44
45    /// Superblock CRC mismatch.
46    #[error("superblock corrupted: CRC mismatch")]
47    SuperblockCorrupted,
48
49    /// Batch position is not sequential.
50    #[error("non-sequential batch: expected position {expected}, got {actual}")]
51    NonSequentialBatch { expected: u64, actual: u64 },
52
53    /// Table not found.
54    #[error("table {0:?} not found")]
55    TableNotFound(TableId),
56
57    /// Page overflow - not enough space for insert.
58    #[error("page overflow: need {needed} bytes, have {available}")]
59    PageOverflow { needed: usize, available: usize },
60
61    /// Internal B+tree invariant violation.
62    #[error("B+tree invariant violation: {0}")]
63    BTreeInvariant(String),
64
65    /// Duplicate key in batch.
66    #[error("duplicate key in batch: {0:?}")]
67    DuplicateKey(Key),
68
69    /// Page not found in cache or on disk.
70    #[error("page {0} not found")]
71    PageNotFound(PageId),
72
73    /// Store is read-only.
74    #[error("store is read-only")]
75    ReadOnly,
76}