1use thiserror::Error;
2
3#[derive(Error, Debug)]
9pub enum SentinelError {
10 #[error("I/O error: {source}")]
12 Io {
13 #[from]
14 source: std::io::Error,
15 },
16
17 #[error("JSON error: {source}")]
19 Json {
20 #[from]
21 source: serde_json::Error,
22 },
23
24 #[error("Document '{id}' not found in collection '{collection}'")]
26 DocumentNotFound {
27 id: String,
28 collection: String,
29 },
30
31 #[error("Collection '{name}' not found in store")]
33 CollectionNotFound {
34 name: String,
35 },
36
37 #[error("Document '{id}' already exists in collection '{collection}'")]
39 DocumentAlreadyExists {
40 id: String,
41 collection: String,
42 },
43
44 #[error("Invalid document ID: {id}")]
46 InvalidDocumentId {
47 id: String,
48 },
49
50 #[error("Invalid collection name: {name}")]
52 InvalidCollectionName {
53 name: String,
54 },
55
56 #[error("Store corruption detected: {reason}")]
58 StoreCorruption {
59 reason: String,
60 },
61
62 #[error("Transaction failed: {reason}")]
64 TransactionFailed {
65 reason: String,
66 },
67
68 #[error("Lock acquisition failed: {reason}")]
70 LockFailed {
71 reason: String,
72 },
73
74 #[error("Cryptographic operation failed: {operation}")]
76 CryptoFailed {
77 operation: String,
78 },
79
80 #[error("Configuration error: {message}")]
82 ConfigError {
83 message: String,
84 },
85
86 #[error("Internal error: {message}")]
88 Internal {
89 message: String,
90 },
91}
92
93pub type Result<T> = std::result::Result<T, SentinelError>;
95
96impl From<sentinel_crypto::CryptoError> for SentinelError {
97 fn from(err: sentinel_crypto::CryptoError) -> Self {
98 Self::CryptoFailed {
99 operation: err.to_string(),
100 }
101 }
102}
103
104#[cfg(test)]
105mod tests {
106 use super::*;
107
108 #[test]
109 fn test_sentinel_error_from_crypto_error() {
110 let crypto_err = sentinel_crypto::CryptoError::Encryption;
111 let sentinel_err: SentinelError = crypto_err.into();
112 match sentinel_err {
113 SentinelError::CryptoFailed {
114 operation,
115 } => {
116 assert!(!operation.is_empty());
117 },
118 _ => panic!("Expected CryptoFailed"),
119 }
120 }
121}