Skip to main content

lutum_protocol/
error.rs

1use std::error::Error as StdError;
2
3use thiserror::Error;
4
5pub type BoxError = Box<dyn StdError + Send + Sync + 'static>;
6
7#[derive(Debug, Error)]
8pub enum AgentError {
9    #[error("invalid model input: {0}")]
10    InvalidModelInput(#[from] crate::conversation::ModelInputValidationError),
11    #[error("budget error: {0}")]
12    Budget(#[source] BoxError),
13    #[error("backend error: {0}")]
14    Backend(#[source] BoxError),
15    #[error("failed to parse tool call: {0}")]
16    ToolCall(#[from] crate::toolset::ToolCallError),
17    #[error("failed to decode JSON: {0}")]
18    Json(#[from] serde_json::Error),
19    #[error("failed to decode structured output: {0}")]
20    StructuredOutput(#[source] serde_json::Error),
21    #[error("other error: {0}")]
22    Other(#[source] BoxError),
23}
24
25impl AgentError {
26    pub fn budget(source: impl StdError + Send + Sync + 'static) -> Self {
27        Self::Budget(Box::new(source))
28    }
29
30    pub fn backend(source: impl StdError + Send + Sync + 'static) -> Self {
31        Self::Backend(Box::new(source))
32    }
33
34    pub fn structured_output(source: serde_json::Error) -> Self {
35        Self::StructuredOutput(source)
36    }
37
38    pub fn other(source: impl StdError + Send + Sync + 'static) -> Self {
39        Self::Other(Box::new(source))
40    }
41}