noxu_collections/
error.rs1use thiserror::Error;
5
6#[derive(Debug, Error)]
9pub enum CollectionError {
10 #[error("database error: {0}")]
12 DatabaseError(#[from] noxu_db::NoxuError),
13
14 #[error("binding error: {0}")]
16 BindingError(String),
17
18 #[error("iterator exhausted")]
20 IteratorExhausted,
21
22 #[error("collection is read-only")]
24 ReadOnly,
25
26 #[error("concurrent modification detected")]
28 ConcurrentModification,
29
30 #[error("illegal state: {0}")]
32 IllegalState(String),
33}
34
35pub type Result<T> = std::result::Result<T, CollectionError>;
37
38#[cfg(test)]
39mod tests {
40 use super::*;
41
42 #[test]
43 fn test_error_display() {
44 let err = CollectionError::ReadOnly;
45 assert_eq!(err.to_string(), "collection is read-only");
46 }
47
48 #[test]
49 fn test_database_error_conversion() {
50 let db_err = noxu_db::NoxuError::DatabaseClosed;
51 let err: CollectionError = db_err.into();
52 assert!(matches!(err, CollectionError::DatabaseError(_)));
53 assert!(err.to_string().contains("database"));
54 }
55
56 #[test]
57 fn test_binding_error() {
58 let err = CollectionError::BindingError("bad conversion".to_string());
59 assert!(err.to_string().contains("binding error"));
60 }
61
62 #[test]
63 fn test_iterator_exhausted() {
64 let err = CollectionError::IteratorExhausted;
65 assert_eq!(err.to_string(), "iterator exhausted");
66 }
67
68 #[test]
69 fn test_illegal_state() {
70 let err =
71 CollectionError::IllegalState("cursor not positioned".to_string());
72 assert!(err.to_string().contains("illegal state"));
73 }
74}