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}
125
126#[derive(Debug, thiserror::Error)]
128pub enum DurableError {
129 #[error("activity failed: {0}")]
131 ActivityFailed(String),
132 #[error("workflow cancelled")]
134 Cancelled,
135 #[error("signal timeout")]
137 SignalTimeout,
138 #[error("continue as new: {0}")]
140 ContinueAsNew(String),
141 #[error(transparent)]
143 Other(Box<dyn std::error::Error + Send + Sync>),
144}
145
146#[derive(Debug, thiserror::Error)]
148pub enum McpError {
149 #[error("connection failed: {0}")]
151 Connection(String),
152 #[error("initialization failed: {0}")]
154 Initialization(String),
155 #[error("tool call failed: {0}")]
157 ToolCall(String),
158 #[error("transport error: {0}")]
160 Transport(String),
161 #[error(transparent)]
163 Other(Box<dyn std::error::Error + Send + Sync>),
164}
165
166#[derive(Debug, thiserror::Error)]
168pub enum HookError {
169 #[error("hook failed: {0}")]
171 Failed(String),
172 #[error(transparent)]
174 Other(Box<dyn std::error::Error + Send + Sync>),
175}
176
177#[derive(Debug, thiserror::Error)]
179pub enum EmbeddingError {
180 #[error("authentication failed: {0}")]
182 Authentication(String),
183 #[error("rate limited, retry after {retry_after:?}")]
185 RateLimit {
186 retry_after: Option<std::time::Duration>,
188 },
189 #[error("invalid request: {0}")]
191 InvalidRequest(String),
192 #[error("network error: {0}")]
194 Network(#[source] Box<dyn std::error::Error + Send + Sync>),
195 #[error(transparent)]
197 Other(Box<dyn std::error::Error + Send + Sync>),
198}
199
200impl EmbeddingError {
201 #[must_use]
203 pub fn is_retryable(&self) -> bool {
204 matches!(self, Self::RateLimit { .. } | Self::Network(_))
205 }
206}
207
208#[derive(Debug, thiserror::Error)]
210pub enum StorageError {
211 #[error("not found: {0}")]
213 NotFound(String),
214 #[error("serialization error: {0}")]
216 Serialization(String),
217 #[error("io error: {0}")]
219 Io(#[from] std::io::Error),
220 #[error(transparent)]
222 Other(Box<dyn std::error::Error + Send + Sync>),
223}
224
225
226#[derive(Debug, thiserror::Error)]
228pub enum SandboxError {
229 #[error("execution failed: {0}")]
231 ExecutionFailed(String),
232 #[error("sandbox error: {0}")]
234 SetupFailed(String),
235 #[error(transparent)]
237 Other(Box<dyn std::error::Error + Send + Sync>),
238}