Skip to main content

recursive/
error.rs

1//! Crate-wide error and Result.
2//!
3//! We keep the error surface small: anything internal collapses into
4//! `Error::Other`, and external integrations (HTTP, JSON, IO) get dedicated
5//! variants so callers can match if they want to recover.
6
7use thiserror::Error;
8
9pub type Result<T, E = Error> = std::result::Result<T, E>;
10
11#[derive(Debug, Error)]
12pub enum Error {
13    #[error("llm error: {0}")]
14    Llm(String),
15
16    #[error("tool `{name}` failed: {message}")]
17    Tool { name: String, message: String },
18
19    #[error("tool `{0}` not found")]
20    UnknownTool(String),
21
22    #[error("invalid tool arguments for `{name}`: {message}")]
23    BadToolArgs { name: String, message: String },
24
25    #[error("agent exceeded step budget ({0})")]
26    StepBudgetExceeded(usize),
27
28    #[error("io: {0}")]
29    Io(#[from] std::io::Error),
30
31    #[error("http: {0}")]
32    Http(#[from] reqwest::Error),
33
34    #[error("json: {0}")]
35    Json(#[from] serde_json::Error),
36
37    #[error("config: {0}")]
38    Config(String),
39
40    #[error("{0}")]
41    Other(String),
42}
43
44impl From<anyhow::Error> for Error {
45    fn from(value: anyhow::Error) -> Self {
46        Error::Other(value.to_string())
47    }
48}