1use thiserror::Error;
8
9#[derive(Debug, Error)]
11pub enum Error {
12 #[error(transparent)]
13 Llm(#[from] LlmError),
14
15 #[error(transparent)]
16 Tool(#[from] ToolError),
17
18 #[error(transparent)]
19 Permission(#[from] PermissionError),
20
21 #[error(transparent)]
22 Config(#[from] ConfigError),
23
24 #[error(transparent)]
25 Io(#[from] std::io::Error),
26
27 #[error("{0}")]
28 Other(String),
29}
30
31#[derive(Debug, Error)]
33pub enum LlmError {
34 #[error("HTTP request failed: {0}")]
35 Http(String),
36
37 #[error("API error (status {status}): {body}")]
38 Api { status: u16, body: String },
39
40 #[error("Rate limited, retry after {retry_after_ms}ms")]
41 RateLimited { retry_after_ms: u64 },
42
43 #[error("Stream interrupted")]
44 StreamInterrupted,
45
46 #[error("Invalid response: {0}")]
47 InvalidResponse(String),
48
49 #[error("Authentication failed: {0}")]
50 AuthError(String),
51
52 #[error("Context window exceeded ({tokens} tokens)")]
53 ContextOverflow { tokens: usize },
54}
55
56#[derive(Debug, Error)]
58pub enum ToolError {
59 #[error("Permission denied: {0}")]
60 PermissionDenied(String),
61
62 #[error("Tool execution failed: {0}")]
63 ExecutionFailed(String),
64
65 #[error("Invalid input: {0}")]
66 InvalidInput(String),
67
68 #[error("Tool not found: {0}")]
69 NotFound(String),
70
71 #[error("IO error: {0}")]
72 Io(#[from] std::io::Error),
73
74 #[error("Operation cancelled")]
75 Cancelled,
76
77 #[error("Timeout after {0}ms")]
78 Timeout(u64),
79}
80
81#[derive(Debug, Error)]
83pub enum PermissionError {
84 #[error("Permission denied by rule: {0}")]
85 DeniedByRule(String),
86
87 #[error("User denied permission for {tool}: {reason}")]
88 UserDenied { tool: String, reason: String },
89}
90
91#[derive(Debug, Error)]
93pub enum ConfigError {
94 #[error("Config file error: {0}")]
95 FileError(String),
96
97 #[error("Invalid config value: {0}")]
98 InvalidValue(String),
99
100 #[error("TOML parse error: {0}")]
101 ParseError(#[from] toml::de::Error),
102}
103
104pub type Result<T> = std::result::Result<T, Error>;