Skip to main content

routex/
error.rs

1/// RoutexError is the canonical error type for the entire library.
2///
3/// Every operation in routex-rs that can fail returns either:
4///   - Result<T, RoutexError>  — for library code
5///   - anyhow::Result<T>       — for CLI code in bin/routex.rs
6#[derive(Debug, thiserror::Error)]
7pub enum RoutexError {
8    /// Config file could not be read or parsed
9    #[error("config error: {0}")]
10    Config(String),
11
12    /// A tool was referenced in agents.yaml but is not registered
13    #[error("tool '{name}' is not registered")]
14    ToolNotFound { name: String },
15
16    /// A tool failed during execution
17    #[error("tool '{name}' failed: {reason}")]
18    ToolFailed { name: String, reason: String },
19
20    /// LLM API call error
21    #[error("llm error: {0}")]
22    LLM(String),
23
24    /// Agent failed during its thinking loop
25    #[error("agent '{id}' failed: {reason}")]
26    AgentFailed { id: String, reason: String },
27
28    /// Dependency cycle detected in agents.yaml
29    /// e.g. agent A depends on B, B depends on A
30    #[error("dependency cycle detected involving agent '{id}'")]
31    CyclicDependency { id: String },
32
33    /// An agent declared a dependency on an agent that doesn't exist
34    #[error("agent '{id}' depends on '{dep}' which does not exist")]
35    UnknownDependency { id: String, dep: String },
36
37    /// HTTP request failed — wraps reqwest errors
38    #[error("http error: {0}")]
39    Http(#[from] reqwest::Error),
40
41    /// JSON serialization/deserialization failed
42    #[error("json error: {0}")]
43    Json(#[from] serde_json::Error),
44
45    /// YAML parsing failed
46    #[error("yaml error: {0}")]
47    Yaml(#[from] serde_yaml::Error),
48
49    /// IO error — reading config files etc
50    #[error("io error: {0}")]
51    Io(#[from] std::io::Error),
52}
53
54pub type Result<T> = std::result::Result<T, RoutexError>;