Skip to main content

motedb/
error.rs

1//! Error types for MoteDB storage engine
2
3use thiserror::Error;
4
5pub type Result<T> = std::result::Result<T, StorageError>;
6
7#[derive(Error, Debug)]
8#[non_exhaustive]
9pub enum StorageError {
10    #[error("IO error: {0}")]
11    Io(#[from] std::io::Error),
12
13    #[error("Serialization error: {0}")]
14    Serialization(String),
15
16    #[error("Fragment error: {0}")]
17    Fragment(String),
18
19    #[error("Index error: {0}")]
20    Index(String),
21
22    #[error("Transaction error: {0}")]
23    Transaction(String),
24
25    #[error("Query error: {0}")]
26    Query(String),
27
28    #[error("Invalid data: {0}")]
29    InvalidData(String),
30
31    #[error("Resource exhausted: {0}")]
32    ResourceExhausted(String),
33    
34    #[error("Data corruption: {0}")]
35    Corruption(String),
36    
37    #[error("Lock error: {0}")]
38    Lock(String),
39    
40    #[error("File not found: {0}")]
41    FileNotFound(std::path::PathBuf),
42    
43    #[error("Corrupted file: {0}")]
44    CorruptedFile(std::path::PathBuf),
45    
46    // SQL-related errors
47    #[error("Parse error: {0}")]
48    ParseError(String),
49    
50    #[error("Type error: {0}")]
51    TypeError(String),
52    
53    #[error("Column not found: {0}")]
54    ColumnNotFound(String),
55    
56    #[error("Table not found: {0}")]
57    TableNotFound(String),
58
59    #[error("Index not found: {0}")]
60    IndexNotFound(String),
61    
62    #[error("Invalid argument: {0}")]
63    InvalidArgument(String),
64    
65    #[error("Unknown function: {0}")]
66    UnknownFunction(String),
67    
68    #[error("Division by zero")]
69    DivisionByZero,
70    
71    #[error("Not implemented: {0}")]
72    NotImplemented(String),
73    
74    /// 🚀 Phase 5: AUTO_INCREMENT overflow error
75    #[error("AUTO_INCREMENT overflow for table '{0}': counter has reached i64::MAX")]
76    AutoIncrementOverflow(String),
77
78    /// Columnar segment store error
79    #[error("Columnar store error: {0}")]
80    Columnar(String),
81
82    /// Segment file corrupted
83    #[error("Segment file corrupted: {0}")]
84    SegmentCorrupted(std::path::PathBuf),
85}
86
87// Alias for compatibility
88pub type MoteDBError = StorageError;
89
90impl From<bincode::Error> for StorageError {
91    fn from(err: bincode::Error) -> Self {
92        StorageError::Serialization(err.to_string())
93    }
94}