daimon_core/error.rs
1//! Error types for the Daimon agent framework.
2
3use thiserror::Error;
4
5/// The central error type for all Daimon operations.
6///
7/// Provider crates should map their transport-specific errors
8/// (HTTP, gRPC, SDK) to [`DaimonError::Model`].
9#[derive(Error, Debug)]
10pub enum DaimonError {
11 /// An error originating from a model provider (API error, bad response, etc.).
12 #[error("model error: {0}")]
13 Model(String),
14
15 /// A tool failed during execution.
16 #[error("tool execution failed for '{tool}': {message}")]
17 ToolExecution {
18 /// Name of the tool that failed.
19 tool: String,
20 /// Description of the failure.
21 message: String,
22 },
23
24 /// The requested tool was not found in the registry.
25 #[error("tool '{0}' not found in registry")]
26 ToolNotFound(String),
27
28 /// Attempted to register a tool with a name that already exists.
29 #[error("duplicate tool '{0}' in registry")]
30 DuplicateTool(String),
31
32 /// The agent builder failed validation (e.g. missing required model).
33 #[error("agent builder validation failed: {0}")]
34 Builder(String),
35
36 /// The agent exceeded the configured maximum number of iterations.
37 #[error("max iterations ({0}) exceeded")]
38 MaxIterations(usize),
39
40 /// A serialization or deserialization error.
41 #[error("serialization error: {0}")]
42 Serialization(#[from] serde_json::Error),
43
44 /// Tool input failed JSON Schema validation.
45 #[error("schema validation failed for tool '{tool}': {errors}")]
46 SchemaValidation {
47 /// Name of the tool whose input failed validation.
48 tool: String,
49 /// Human-readable description of validation errors.
50 errors: String,
51 },
52
53 /// A stream was closed before completing.
54 #[error("stream closed unexpectedly")]
55 StreamClosed,
56
57 /// A request timed out.
58 #[error("request timed out after {0:?}")]
59 Timeout(std::time::Duration),
60
61 /// The operation was cancelled via a cancellation token.
62 #[error("operation cancelled")]
63 Cancelled,
64
65 /// An orchestration error (chain or graph execution failure).
66 #[error("orchestration error: {0}")]
67 Orchestration(String),
68
69 /// An MCP protocol error.
70 #[error("MCP error: {0}")]
71 Mcp(String),
72
73 /// The agent exceeded the configured spending budget.
74 #[error("budget exceeded: ${spent:.6} spent, limit was ${limit:.6}")]
75 BudgetExceeded {
76 /// How much has been spent so far (USD).
77 spent: f64,
78 /// The configured limit (USD).
79 limit: f64,
80 },
81
82 /// An input or output guardrail blocked the request.
83 #[error("guardrail blocked: {0}")]
84 GuardrailBlocked(String),
85
86 /// A catch-all for other errors.
87 #[error("{0}")]
88 Other(String),
89}
90
91/// A type alias for `Result<T, DaimonError>`.
92pub type Result<T> = std::result::Result<T, DaimonError>;