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
37/// Convenience alias — every fallible function in this crate returns this.
38pub type IsamResult<T> = Result<T, IsamError>;