Skip to main content

highlandcows_isam/
error.rs

1/// All errors that can be produced by this library.
2///
3/// `thiserror::Error` generates the boilerplate `std::error::Error` impl,
4/// and the `#[error("...")]` attribute defines the human-readable message
5/// for each variant.
6use thiserror::Error;
7
8#[derive(Debug, Error)]
9pub enum IsamError {
10    /// Wraps any std::io::Error (e.g. file not found, permission denied).
11    /// The `#[from]` attribute lets the `?` operator convert io::Error
12    /// automatically — no explicit `.map_err(...)` needed.
13    #[error("I/O error: {0}")]
14    Io(#[from] std::io::Error),
15
16    /// Wraps bincode serialization/deserialization errors.
17    #[error("serialization error: {0}")]
18    Bincode(#[from] Box<bincode::ErrorKind>),
19
20    /// The requested key does not exist (used for update on missing key).
21    #[error("key not found")]
22    KeyNotFound,
23
24    /// Attempted to insert a key that already exists in the index.
25    #[error("duplicate key")]
26    DuplicateKey,
27
28    /// The index file is corrupt or was created by an incompatible version.
29    #[error("index file is corrupt: {0}")]
30    CorruptIndex(String),
31
32    /// A thread panicked while holding the database lock.
33    #[error("mutex poisoned: a thread panicked while holding the database lock")]
34    LockPoisoned,
35
36    /// No secondary index with the given name is registered on this database.
37    #[error("secondary index not found: {0}")]
38    IndexNotFound(String),
39
40    /// The database is in single-user mode and the calling thread is not the owner.
41    #[error("database is in single-user mode")]
42    SingleUserMode,
43
44    /// Timed out waiting to acquire single-user mode (in-flight transaction did not finish in time).
45    #[error("timed out waiting to acquire single-user mode")]
46    Timeout,
47}
48
49/// Convenience alias — every fallible function in this crate returns this.
50pub type IsamResult<T> = Result<T, IsamError>;