Skip to main content

synwire_core/agents/
error.rs

1//! Error types for agent operations.
2
3use thiserror::Error;
4
5/// Top-level error type for agent operations.
6#[derive(Error, Debug, Clone)]
7#[non_exhaustive]
8pub enum AgentError {
9    /// Model API error.
10    #[error("Model error: {0}")]
11    Model(#[from] ModelError),
12
13    /// Tool execution error.
14    #[error("Tool error: {0}")]
15    Tool(String),
16
17    /// Execution strategy error.
18    #[error("Strategy error: {0}")]
19    Strategy(String),
20
21    /// Middleware error.
22    #[error("Middleware error: {0}")]
23    Middleware(String),
24
25    /// Directive execution error.
26    #[error("Directive error: {0}")]
27    Directive(String),
28
29    /// VFS operation error.
30    #[error("VFS error: {0}")]
31    Vfs(String),
32
33    /// Session management error.
34    #[error("Session error: {0}")]
35    Session(String),
36
37    /// Caught panic with payload.
38    #[error("Panic: {0}")]
39    Panic(String),
40
41    /// Cost budget exceeded.
42    #[error("Budget exceeded: ${0:.2}")]
43    BudgetExceeded(f64),
44}
45
46/// Model API error subtypes with retryability metadata.
47#[derive(Error, Debug, Clone)]
48#[non_exhaustive]
49pub enum ModelError {
50    /// Authentication failure - not retryable.
51    #[error("Authentication failed: {0}")]
52    Authentication(String),
53
54    /// Billing or quota error - not retryable.
55    #[error("Billing error: {0}")]
56    Billing(String),
57
58    /// Rate limit exceeded - retryable.
59    #[error("Rate limited: {0}")]
60    RateLimit(String),
61
62    /// Provider server error - retryable.
63    #[error("Server error: {0}")]
64    ServerError(String),
65
66    /// Invalid request - not retryable.
67    #[error("Invalid request: {0}")]
68    InvalidRequest(String),
69
70    /// Output exceeded token limit - not retryable.
71    #[error("Max output tokens exceeded")]
72    MaxOutputTokens,
73}
74
75impl ModelError {
76    /// Returns whether this error is retryable.
77    #[must_use]
78    pub const fn is_retryable(&self) -> bool {
79        matches!(self, Self::RateLimit(_) | Self::ServerError(_))
80    }
81}