rustlite_core/
error.rs

1//! Error types for RustLite.
2
3use std::fmt;
4
5/// The main error type for RustLite operations.
6#[derive(Debug)]
7pub enum Error {
8    /// A lock was poisoned (internal error)
9    LockPoisoned,
10
11    /// I/O error
12    Io(std::io::Error),
13
14    /// Serialization/deserialization error
15    Serialization(String),
16
17    /// Storage engine error
18    Storage(String),
19
20    /// Transaction error
21    Transaction(String),
22
23    /// Invalid operation
24    InvalidOperation(String),
25
26    /// Invalid input (e.g., invalid SQL query)
27    InvalidInput(String),
28
29    /// Not found
30    NotFound,
31
32    /// Data corruption detected
33    Corruption(String),
34}
35
36impl fmt::Display for Error {
37    fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
38        match self {
39            Error::LockPoisoned => write!(f, "Lock poisoned"),
40            Error::Io(e) => write!(f, "I/O error: {}", e),
41            Error::Serialization(msg) => write!(f, "Serialization error: {}", msg),
42            Error::Storage(msg) => write!(f, "Storage error: {}", msg),
43            Error::Transaction(msg) => write!(f, "Transaction error: {}", msg),
44            Error::InvalidOperation(msg) => write!(f, "Invalid operation: {}", msg),
45            Error::InvalidInput(msg) => write!(f, "Invalid input: {}", msg),
46            Error::NotFound => write!(f, "Not found"),
47            Error::Corruption(msg) => write!(f, "Data corruption: {}", msg),
48        }
49    }
50}
51
52impl std::error::Error for Error {
53    fn source(&self) -> Option<&(dyn std::error::Error + 'static)> {
54        match self {
55            Error::Io(e) => Some(e),
56            _ => None,
57        }
58    }
59}
60
61impl From<std::io::Error> for Error {
62    fn from(err: std::io::Error) -> Self {
63        Error::Io(err)
64    }
65}
66
67/// A specialized `Result` type for RustLite operations.
68pub type Result<T> = std::result::Result<T, Error>;