use thiserror::Error;
#[derive(Debug, Error)]
pub enum CollectionError {
#[error("database error: {0}")]
DatabaseError(#[from] noxu_db::NoxuError),
#[error("binding error: {0}")]
BindingError(String),
#[error("iterator exhausted")]
IteratorExhausted,
#[error("collection is read-only")]
ReadOnly,
#[error("concurrent modification detected")]
ConcurrentModification,
#[error("illegal state: {0}")]
IllegalState(String),
}
pub type Result<T> = std::result::Result<T, CollectionError>;
#[cfg(test)]
mod tests {
use super::*;
#[test]
fn test_error_display() {
let err = CollectionError::ReadOnly;
assert_eq!(err.to_string(), "collection is read-only");
}
#[test]
fn test_database_error_conversion() {
let db_err = noxu_db::NoxuError::DatabaseClosed;
let err: CollectionError = db_err.into();
assert!(matches!(err, CollectionError::DatabaseError(_)));
assert!(err.to_string().contains("database"));
}
#[test]
fn test_binding_error() {
let err = CollectionError::BindingError("bad conversion".to_string());
assert!(err.to_string().contains("binding error"));
}
#[test]
fn test_iterator_exhausted() {
let err = CollectionError::IteratorExhausted;
assert_eq!(err.to_string(), "iterator exhausted");
}
#[test]
fn test_illegal_state() {
let err =
CollectionError::IllegalState("cursor not positioned".to_string());
assert!(err.to_string().contains("illegal state"));
}
}