1use std::time::Duration;
4
5#[derive(Debug, thiserror::Error)]
7pub enum ProviderError {
8 #[error("network error: {0}")]
11 Network(#[source] Box<dyn std::error::Error + Send + Sync>),
12 #[error("rate limited, retry after {retry_after:?}")]
14 RateLimit {
15 retry_after: Option<Duration>,
17 },
18 #[error("model loading: {0}")]
20 ModelLoading(String),
21 #[error("timeout after {0:?}")]
23 Timeout(Duration),
24 #[error("service unavailable: {0}")]
26 ServiceUnavailable(String),
27
28 #[error("authentication failed: {0}")]
31 Authentication(String),
32 #[error("invalid request: {0}")]
34 InvalidRequest(String),
35 #[error("model not found: {0}")]
37 ModelNotFound(String),
38 #[error("insufficient resources: {0}")]
40 InsufficientResources(String),
41
42 #[error("stream error: {0}")]
45 StreamError(String),
46 #[error(transparent)]
48 Other(Box<dyn std::error::Error + Send + Sync>),
49}
50
51impl ProviderError {
52 #[must_use]
54 pub fn is_retryable(&self) -> bool {
55 matches!(
56 self,
57 Self::Network(_)
58 | Self::RateLimit { .. }
59 | Self::ModelLoading(_)
60 | Self::Timeout(_)
61 | Self::ServiceUnavailable(_)
62 )
63 }
64}
65
66#[derive(Debug, thiserror::Error)]
68pub enum ToolError {
69 #[error("tool not found: {0}")]
71 NotFound(String),
72 #[error("invalid input: {0}")]
74 InvalidInput(String),
75 #[error("execution failed: {0}")]
77 ExecutionFailed(#[source] Box<dyn std::error::Error + Send + Sync>),
78 #[error("permission denied: {0}")]
80 PermissionDenied(String),
81 #[error("cancelled")]
83 Cancelled,
84 #[error("model retry requested: {0}")]
89 ModelRetry(String),
90}
91
92#[derive(Debug, thiserror::Error)]
94pub enum ContextError {
95 #[error("compaction failed: {0}")]
97 CompactionFailed(String),
98 #[error("provider error during summarization: {0}")]
100 Provider(#[from] ProviderError),
101}
102
103#[derive(Debug, thiserror::Error)]
105pub enum LoopError {
106 #[error("provider error: {0}")]
108 Provider(#[from] ProviderError),
109 #[error("tool error: {0}")]
111 Tool(#[from] ToolError),
112 #[error("context error: {0}")]
114 Context(#[from] ContextError),
115 #[error("max turns reached ({0})")]
117 MaxTurns(usize),
118 #[error("terminated by hook: {0}")]
120 HookTerminated(String),
121 #[error("cancelled")]
123 Cancelled,
124 #[error("usage limit exceeded: {0}")]
126 UsageLimitExceeded(String),
127}
128
129#[derive(Debug, thiserror::Error)]
131pub enum DurableError {
132 #[error("activity failed: {0}")]
134 ActivityFailed(String),
135 #[error("workflow cancelled")]
137 Cancelled,
138 #[error("signal timeout")]
140 SignalTimeout,
141 #[error("continue as new: {0}")]
143 ContinueAsNew(String),
144 #[error(transparent)]
146 Other(Box<dyn std::error::Error + Send + Sync>),
147}
148
149#[derive(Debug, thiserror::Error)]
151pub enum McpError {
152 #[error("connection failed: {0}")]
154 Connection(String),
155 #[error("initialization failed: {0}")]
157 Initialization(String),
158 #[error("tool call failed: {0}")]
160 ToolCall(String),
161 #[error("transport error: {0}")]
163 Transport(String),
164 #[error(transparent)]
166 Other(Box<dyn std::error::Error + Send + Sync>),
167}
168
169#[derive(Debug, thiserror::Error)]
171pub enum HookError {
172 #[error("hook failed: {0}")]
174 Failed(String),
175 #[error(transparent)]
177 Other(Box<dyn std::error::Error + Send + Sync>),
178}
179
180#[derive(Debug, thiserror::Error)]
182pub enum EmbeddingError {
183 #[error("authentication failed: {0}")]
185 Authentication(String),
186 #[error("rate limited, retry after {retry_after:?}")]
188 RateLimit {
189 retry_after: Option<std::time::Duration>,
191 },
192 #[error("invalid request: {0}")]
194 InvalidRequest(String),
195 #[error("network error: {0}")]
197 Network(#[source] Box<dyn std::error::Error + Send + Sync>),
198 #[error(transparent)]
200 Other(Box<dyn std::error::Error + Send + Sync>),
201}
202
203impl EmbeddingError {
204 #[must_use]
206 pub fn is_retryable(&self) -> bool {
207 matches!(self, Self::RateLimit { .. } | Self::Network(_))
208 }
209}
210
211#[derive(Debug, thiserror::Error)]
213pub enum StorageError {
214 #[error("not found: {0}")]
216 NotFound(String),
217 #[error("serialization error: {0}")]
219 Serialization(String),
220 #[error("io error: {0}")]
222 Io(#[from] std::io::Error),
223 #[error(transparent)]
225 Other(Box<dyn std::error::Error + Send + Sync>),
226}
227
228#[derive(Debug, thiserror::Error)]
230pub enum SandboxError {
231 #[error("execution failed: {0}")]
233 ExecutionFailed(String),
234 #[error("sandbox error: {0}")]
236 SetupFailed(String),
237 #[error(transparent)]
239 Other(Box<dyn std::error::Error + Send + Sync>),
240}