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
35 #[error("Security screening failed: {0}")]
37 ScreeningFailed(String),
38
39 #[error("Context blocked: {0}")]
41 Blocked(String),
42
43 #[error("IO error: {0}")]
45 Io(#[from] std::io::Error),
46
47 #[error("Operation timed out: {0}")]
49 Timeout(String),
50
51 #[error("Configuration error: {0}")]
53 Config(String),
54
55 #[error("Protocol error: {0}")]
57 Protocol(String),
58
59 #[error("Internal error: {0}")]
61 Internal(String),
62}
63
64impl ContextError {
65 pub fn is_not_found(&self) -> bool {
67 matches!(self, Self::NotFound(_))
68 }
69
70 pub fn is_security_error(&self) -> bool {
72 matches!(self, Self::ScreeningFailed(_) | Self::Blocked(_))
73 }
74}
75#[cfg(feature = "persistence")]impl From<sled::Error> for ContextError {
76 fn from(err: sled::Error) -> Self {
77 Self::Storage(err.to_string())
78 }
79}