Skip to main content

qdb_rs/
error.rs

1//! Error types for QDB operations
2
3use thiserror::Error;
4
5/// Error type for QDB operations
6#[derive(Error, Debug)]
7pub enum QdbError {
8    /// Key not found in database
9    #[error("Key not found: {0}")]
10    KeyNotFound(String),
11
12    /// Key already exists (for insert operations)
13    #[error("Key already exists: {0}")]
14    KeyExists(String),
15
16    /// Invalid key format
17    #[error("Invalid key format: {0}")]
18    InvalidKey(String),
19
20    /// Value serialization/deserialization error
21    #[error("Value error: {0}")]
22    ValueError(String),
23
24    /// QFT format error
25    #[error("QFT error: {0}")]
26    QftError(#[from] qft::QftError),
27
28    /// I/O error
29    #[error("I/O error: {0}")]
30    IoError(#[from] std::io::Error),
31
32    /// Serialization error
33    #[error("Serialization error: {0}")]
34    SerializationError(String),
35
36    /// Transaction error
37    #[error("Transaction error: {0}")]
38    TransactionError(String),
39
40    /// Query error
41    #[error("Query error: {0}")]
42    QueryError(String),
43
44    /// Backend error
45    #[error("Backend error: {0}")]
46    BackendError(String),
47
48    /// Checksum mismatch
49    #[error("Checksum mismatch for key: {0}")]
50    ChecksumMismatch(String),
51
52    /// Golay decode failed
53    #[error("Golay error correction failed")]
54    GolayDecodeFailed,
55
56    /// Database is read-only
57    #[error("Database is read-only")]
58    ReadOnly,
59
60    /// Database is closed
61    #[error("Database is closed")]
62    Closed,
63
64    /// Concurrent modification detected
65    #[error("Concurrent modification detected for key: {0}")]
66    ConcurrentModification(String),
67
68    /// Index error
69    #[error("Index error: {0}")]
70    IndexError(String),
71
72    /// Capacity exceeded
73    #[error("Capacity exceeded: {0}")]
74    CapacityExceeded(String),
75
76    /// Invalid input
77    #[error("Invalid input: {0}")]
78    InvalidInput(String),
79
80    /// Vector store error
81    #[error("Vector store error: {0}")]
82    VectorError(String),
83}
84
85/// Result type alias for QDB operations
86pub type Result<T> = std::result::Result<T, QdbError>;
87
88impl From<serde_json::Error> for QdbError {
89    fn from(e: serde_json::Error) -> Self {
90        QdbError::SerializationError(e.to_string())
91    }
92}