1use thiserror::Error;
4
5pub type Result<T> = std::result::Result<T, Error>;
7
8#[derive(Error, Debug)]
10pub enum Error {
11 #[error("Configuration error: {0}")]
13 Config(#[from] ConfigError),
14
15 #[error("LLM error: {0}")]
17 Llm(#[from] LlmError),
18
19 #[error("Tool error: {0}")]
21 Tool(#[from] ToolError),
22
23 #[error("Agent error: {0}")]
25 Agent(#[from] AgentError),
26
27 #[error("Trajectory error: {0}")]
29 Trajectory(#[from] TrajectoryError),
30
31 #[error("IO error: {0}")]
33 Io(#[from] std::io::Error),
34
35 #[error("Serialization error: {0}")]
37 Serialization(#[from] serde_json::Error),
38
39 #[error("HTTP error: {0}")]
41 Http(#[from] reqwest::Error),
42
43 #[error("Database error: {0}")]
45 Database(#[from] rusqlite::Error),
46
47 #[error("Language error: {0}")]
49 Language(#[from] tree_sitter::LanguageError),
50
51 #[error("Timeout error: {0}")]
53 Timeout(#[from] tokio::time::error::Elapsed),
54
55 #[error("{0}")]
57 Generic(String),
58}
59
60#[derive(Error, Debug)]
62pub enum ConfigError {
63 #[error("Missing required field: {field}")]
64 MissingField { field: String },
65
66 #[error("Invalid value for field '{field}': {value}")]
67 InvalidValue { field: String, value: String },
68
69 #[error("File not found: {path}")]
70 FileNotFound { path: String },
71
72 #[error("Invalid configuration format")]
73 InvalidFormat,
74
75 #[error("No configuration found")]
76 NoConfigFound,
77}
78
79#[derive(Error, Debug)]
81pub enum LlmError {
82 #[error("Authentication failed: {message}")]
83 Authentication { message: String },
84
85 #[error("Rate limit exceeded")]
86 RateLimit,
87
88 #[error("Model not found: {model}")]
89 ModelNotFound { model: String },
90
91 #[error("Invalid request: {message}")]
92 InvalidRequest { message: String },
93
94 #[error("API error: {status} - {message}")]
95 ApiError { status: u16, message: String },
96
97 #[error("Network error: {message}")]
98 Network { message: String },
99}
100
101#[derive(Error, Debug)]
103pub enum ToolError {
104 #[error("Tool not found: {name}")]
105 NotFound { name: String },
106
107 #[error("Tool execution failed: {name} - {message}")]
108 ExecutionFailed { name: String, message: String },
109
110 #[error("Invalid tool parameters: {message}")]
111 InvalidParameters { message: String },
112
113 #[error("Tool timeout: {name}")]
114 Timeout { name: String },
115}
116
117#[derive(Error, Debug)]
119pub enum AgentError {
120 #[error("Maximum steps exceeded: {max_steps}")]
121 MaxStepsExceeded { max_steps: usize },
122
123 #[error("Task execution failed: {message}")]
124 TaskFailed { message: String },
125
126 #[error("Invalid task: {message}")]
127 InvalidTask { message: String },
128
129 #[error("Agent not initialized")]
130 NotInitialized,
131}
132
133#[derive(Error, Debug)]
135pub enum TrajectoryError {
136 #[error("Failed to record trajectory: {message}")]
137 RecordingFailed { message: String },
138
139 #[error("Failed to load trajectory: {path}")]
140 LoadFailed { path: String },
141
142 #[error("Invalid trajectory format")]
143 InvalidFormat,
144}
145
146impl From<String> for Error {
147 fn from(msg: String) -> Self {
148 Error::Generic(msg)
149 }
150}
151
152impl From<&str> for Error {
153 fn from(msg: &str) -> Self {
154 Error::Generic(msg.to_string())
155 }
156}