Skip to main content

nodedb_lite/
error.rs

1//! Error types for NodeDB-Lite.
2
3/// Errors specific to the Lite embedded engine.
4#[derive(Debug, thiserror::Error)]
5pub enum LiteError {
6    #[error("storage error: {detail}")]
7    Storage { detail: String },
8
9    #[error("storage backend returned poison lock")]
10    LockPoisoned,
11
12    #[error("async task join failed: {detail}")]
13    JoinError { detail: String },
14
15    #[error("serialization error: {detail}")]
16    Serialization { detail: String },
17
18    #[error("namespace {ns} not recognized")]
19    InvalidNamespace { ns: u8 },
20
21    #[error("bad request: {detail}")]
22    BadRequest { detail: String },
23
24    #[error("sync error: {detail}")]
25    Sync { detail: String },
26
27    #[error("query error: {0}")]
28    Query(String),
29
30    #[error("Arrow type conversion: expected {expected}, got {got}")]
31    ArrowTypeConversion { expected: String, got: String },
32}
33
34impl From<redb::Error> for LiteError {
35    fn from(e: redb::Error) -> Self {
36        Self::Storage {
37            detail: e.to_string(),
38        }
39    }
40}
41
42impl From<redb::DatabaseError> for LiteError {
43    fn from(e: redb::DatabaseError) -> Self {
44        Self::Storage {
45            detail: e.to_string(),
46        }
47    }
48}
49
50impl From<redb::TransactionError> for LiteError {
51    fn from(e: redb::TransactionError) -> Self {
52        Self::Storage {
53            detail: e.to_string(),
54        }
55    }
56}
57
58impl From<redb::StorageError> for LiteError {
59    fn from(e: redb::StorageError) -> Self {
60        Self::Storage {
61            detail: e.to_string(),
62        }
63    }
64}
65
66impl From<nodedb_types::columnar::SchemaError> for LiteError {
67    fn from(e: nodedb_types::columnar::SchemaError) -> Self {
68        Self::BadRequest {
69            detail: e.to_string(),
70        }
71    }
72}
73
74impl From<LiteError> for nodedb_types::error::NodeDbError {
75    fn from(e: LiteError) -> Self {
76        nodedb_types::error::NodeDbError::storage(e)
77    }
78}
79
80#[cfg(test)]
81mod tests {
82    use super::*;
83
84    #[test]
85    fn lite_error_display() {
86        let e = LiteError::Storage {
87            detail: "disk full".into(),
88        };
89        assert!(e.to_string().contains("disk full"));
90    }
91
92    #[test]
93    fn lite_error_converts_to_nodedb_error() {
94        let e = LiteError::Storage {
95            detail: "test".into(),
96        };
97        let ndb: nodedb_types::error::NodeDbError = e.into();
98        assert!(ndb.to_string().contains("test"));
99    }
100}