1use thiserror::Error;
4
5pub type Result<T> = std::result::Result<T, ContextError>;
7
8pub type ContextResult<T> = std::result::Result<T, ContextError>;
10
11#[derive(Error, Debug)]
13pub enum ContextError {
14 #[error("Context not found: {0}")]
16 NotFound(String),
17
18 #[error("Storage error: {0}")]
20 Storage(String),
21
22 #[error("Serialization error: {0}")]
24 Serialization(#[from] serde_json::Error),
25
26 #[error("Invalid query: {0}")]
28 InvalidQuery(String),
29
30 #[error("Context has expired: {0}")]
32 Expired(String),
33
34 #[error("Security screening failed: {0}")]
36 ScreeningFailed(String),
37
38 #[error("Context blocked: {0}")]
40 Blocked(String),
41
42 #[error("IO error: {0}")]
44 Io(#[from] std::io::Error),
45
46 #[error("Operation timed out: {0}")]
48 Timeout(String),
49
50 #[error("Configuration error: {0}")]
52 Config(String),
53
54 #[error("Protocol error: {0}")]
56 Protocol(String),
57
58 #[error("Internal error: {0}")]
60 Internal(String),
61}
62
63impl ContextError {
64 pub fn is_not_found(&self) -> bool {
66 matches!(self, Self::NotFound(_))
67 }
68
69 pub fn is_security_error(&self) -> bool {
71 matches!(self, Self::ScreeningFailed(_) | Self::Blocked(_))
72 }
73}
74#[cfg(feature = "persistence")]
75impl From<sled::Error> for ContextError {
76 fn from(err: sled::Error) -> Self {
77 Self::Storage(err.to_string())
78 }
79}