byodb_rust/core/error.rs
1//! Errors returned by functions in the [`crate::core`] module.
2
3use std::io;
4
5/// An error encountered when interacting with a B+ tree.
6pub type TreeError = NodeError;
7
8/// An error encountered when interacting with a B+ tree node.
9#[derive(thiserror::Error, Debug)]
10pub enum NodeError {
11 /// Key size exceeds maximum limit.
12 #[error("Key size exceeds maximum limit: key length {0} exceeds MAX_KEY_SIZE")]
13 MaxKeySize(usize), // usize is key length
14 /// Value size exceeds maximum limit.
15 #[error("Value size exceeds maximum limit: value length {0} exceeds MAX_VALUE_SIZE")]
16 MaxValueSize(usize), // usize is value length
17 /// Unexpected node type. This represents data corruption.
18 #[error("Unexpected node type: {0:#b}")]
19 UnexpectedNodeType(u16), // u16 is the node type
20 /// Key already exists.
21 #[error("Key already exists")]
22 AlreadyExists,
23 /// Key not found.
24 #[error("Key not found")]
25 KeyNotFound,
26}
27
28/// An error encountered when interacting with the memory map.
29#[derive(thiserror::Error, Debug)]
30pub enum MmapError {
31 /// An IO error encountered when interacting with the memory-mapped file.
32 #[error(transparent)]
33 IOError(#[from] io::Error),
34 /// The file is invalid and cannot be memory-mapped.
35 #[error("Invalid file: {0}")]
36 InvalidFile(String),
37}