trae_agent_rs_core/
error.rs1use 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
40
41 #[error("HTTP error: {0}")]
43 Http(#[from] reqwest::Error),
44
45 #[error("Database error: {0}")]
47 Database(#[from] rusqlite::Error),
48
49 #[error("Language error: {0}")]
51 Language(#[from] tree_sitter::LanguageError),
52
53 #[error("Timeout error: {0}")]
55 Timeout(#[from] tokio::time::error::Elapsed),
56
57 #[error("{0}")]
59 Generic(String),
60}
61
62#[derive(Error, Debug)]
64pub enum ConfigError {
65 #[error("Missing required field: {field}")]
66 MissingField { field: String },
67
68 #[error("Invalid value for field '{field}': {value}")]
69 InvalidValue { field: String, value: String },
70
71 #[error("File not found: {path}")]
72 FileNotFound { path: String },
73
74 #[error("Invalid configuration format")]
75 InvalidFormat,
76
77 #[error("No configuration found")]
78 NoConfigFound,
79}
80
81#[derive(Error, Debug)]
83pub enum LlmError {
84 #[error("Authentication failed: {message}")]
85 Authentication { message: String },
86
87 #[error("Rate limit exceeded")]
88 RateLimit,
89
90 #[error("Model not found: {model}")]
91 ModelNotFound { model: String },
92
93 #[error("Invalid request: {message}")]
94 InvalidRequest { message: String },
95
96 #[error("API error: {status} - {message}")]
97 ApiError { status: u16, message: String },
98
99 #[error("Network error: {message}")]
100 Network { message: String },
101}
102
103#[derive(Error, Debug)]
105pub enum ToolError {
106 #[error("Tool not found: {name}")]
107 NotFound { name: String },
108
109 #[error("Tool execution failed: {name} - {message}")]
110 ExecutionFailed { name: String, message: String },
111
112 #[error("Invalid tool parameters: {message}")]
113 InvalidParameters { message: String },
114
115 #[error("Tool timeout: {name}")]
116 Timeout { name: String },
117}
118
119#[derive(Error, Debug)]
121pub enum AgentError {
122 #[error("Maximum steps exceeded: {max_steps}")]
123 MaxStepsExceeded { max_steps: usize },
124
125 #[error("Task execution failed: {message}")]
126 TaskFailed { message: String },
127
128 #[error("Invalid task: {message}")]
129 InvalidTask { message: String },
130
131 #[error("Agent not initialized")]
132 NotInitialized,
133}
134
135#[derive(Error, Debug)]
137pub enum TrajectoryError {
138 #[error("Failed to record trajectory: {message}")]
139 RecordingFailed { message: String },
140
141 #[error("Failed to load trajectory: {path}")]
142 LoadFailed { path: String },
143
144 #[error("Invalid trajectory format")]
145 InvalidFormat,
146}
147
148impl From<String> for Error {
149 fn from(msg: String) -> Self {
150 Error::Generic(msg)
151 }
152}
153
154impl From<&str> for Error {
155 fn from(msg: &str) -> Self {
156 Error::Generic(msg.to_string())
157 }
158}