1use thiserror::Error;
4
5#[derive(Error, Debug, Clone)]
7pub enum DbError {
8 #[error("Document not found: {0}")]
9 DocumentNotFound(String),
10
11 #[error("Path not found: {0}")]
12 PathNotFound(String),
13
14 #[error("Type mismatch: expected {expected}, found {found}")]
15 TypeMismatch { expected: String, found: String },
16
17 #[error("Invalid index: {index} (length: {length})")]
18 IndexOutOfBounds { index: usize, length: usize },
19
20 #[error("Invalid path segment: {0}")]
21 InvalidPath(String),
22
23 #[error("Serialization error: {0}")]
24 SerializationError(String),
25
26 #[error("Operation not supported: {0}")]
27 UnsupportedOperation(String),
28
29 #[error("Concurrent modification detected")]
30 ConcurrentModification,
31}
32
33impl From<serde_json::Error> for DbError {
34 fn from(err: serde_json::Error) -> Self {
35 DbError::SerializationError(err.to_string())
36 }
37}
38
39pub type Result<T> = std::result::Result<T, DbError>;