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