1use thiserror::Error;
5
6pub type Result<T, E = Error> = std::result::Result<T, E>;
7
8#[derive(Debug, Error)]
9pub enum Error {
10 #[error("I/O error: {0}")]
11 Io(#[from] std::io::Error),
12
13 #[error("JSON error: {0}")]
14 Json(#[from] serde_json::Error),
15
16 #[error("configuration error: {0}")]
17 Config(String),
18
19 #[error("invalid input: {0}")]
20 InvalidInput(String),
21
22 #[error("not found: {0}")]
23 NotFound(String),
24
25 #[error("unauthorized: {0}")]
26 Unauthorized(String),
27
28 #[error("security policy violation: {0}")]
31 Security(String),
32
33 #[error("database error: {0}")]
34 Db(String),
35
36 #[error("container error: {0}")]
37 Container(String),
38
39 #[error("LLM provider error: {0}")]
40 Llm(String),
41
42 #[error("MCP error: {0}")]
43 Mcp(String),
44
45 #[error("channel error: {0}")]
46 Channel(String),
47
48 #[error("timeout: {0}")]
49 Timeout(String),
50
51 #[error("{0}")]
52 Other(String),
53}
54
55impl Error {
56 pub fn invalid(msg: impl Into<String>) -> Self {
57 Self::InvalidInput(msg.into())
58 }
59 pub fn security(msg: impl Into<String>) -> Self {
60 Self::Security(msg.into())
61 }
62 pub fn other(msg: impl Into<String>) -> Self {
63 Self::Other(msg.into())
64 }
65}