Skip to main content

agent_sdk/
error.rs

1use thiserror::Error;
2
3/// Errors that can occur during agent execution.
4#[derive(Error, Debug)]
5pub enum AgentError {
6    #[error("API error: {0}")]
7    Api(String),
8
9    #[error("Authentication failed: {0}")]
10    AuthenticationFailed(String),
11
12    #[error("Billing error: {0}")]
13    BillingError(String),
14
15    #[error("Rate limited: {0}")]
16    RateLimited(String),
17
18    #[error("Invalid request: {0}")]
19    InvalidRequest(String),
20
21    #[error("Server error: {0}")]
22    ServerError(String),
23
24    #[error("Process error: {0}")]
25    Process(String),
26
27    #[error("Session not found: {0}")]
28    SessionNotFound(String),
29
30    #[error("Hook error: {0}")]
31    Hook(#[from] starpod_hooks::HookError),
32
33    #[error("MCP server error: {0}")]
34    McpServer(String),
35
36    #[error("Tool execution error: {0}")]
37    ToolExecution(String),
38
39    #[error("Permission denied: tool={tool}, reason={reason}")]
40    PermissionDenied { tool: String, reason: String },
41
42    #[error("Max turns exceeded: {0}")]
43    MaxTurnsExceeded(u32),
44
45    #[error("Max budget exceeded: ${0:.4}")]
46    MaxBudgetExceeded(f64),
47
48    #[error("Serialization error: {0}")]
49    Serialization(#[from] serde_json::Error),
50
51    #[error("IO error: {0}")]
52    Io(#[from] std::io::Error),
53
54    #[error("HTTP error: {0}")]
55    Http(#[from] reqwest::Error),
56
57    #[error("Regex error: {0}")]
58    Regex(#[from] regex::Error),
59
60    #[error("Cancelled")]
61    Cancelled,
62}
63
64pub type Result<T> = std::result::Result<T, AgentError>;