mcp_servers/coding/
error.rs1use thiserror::Error;
7
8pub use crate::file_ops::FileError;
9
10#[doc = include_str!("../docs/coding_error.md")]
11#[derive(Debug, Error)]
12pub enum CodingError {
13 #[error(transparent)]
15 File(#[from] FileError),
16
17 #[error(transparent)]
19 Bash(#[from] BashError),
20
21 #[error(transparent)]
23 Grep(#[from] GrepError),
24
25 #[error(transparent)]
27 AstGrep(#[from] AstGrepError),
28
29 #[error(transparent)]
31 Find(#[from] FindError),
32
33 #[error(transparent)]
35 ListFiles(#[from] ListFilesError),
36
37 #[error(transparent)]
39 WebFetch(#[from] WebFetchError),
40
41 #[error(transparent)]
43 WebSearch(#[from] WebSearchError),
44
45 #[error("{0}")]
47 NotConfigured(String),
48}
49
50#[derive(Debug, Error)]
52pub enum BashError {
53 #[error("{0}")]
55 Forbidden(String),
56
57 #[error("Timeout cannot exceed 600000ms (10 minutes)")]
59 TimeoutTooLarge,
60
61 #[error("Failed to execute command '{command}': {reason}")]
63 SpawnFailed { command: String, reason: String },
64
65 #[error("Invalid regex pattern: {0}")]
67 InvalidRegex(String),
68
69 #[error("Failed to join background task: {0}")]
71 JoinFailed(String),
72
73 #[error("Shell ID not found: {0}")]
75 ShellNotFound(String),
76
77 #[error("Wait failed: {0}")]
79 WaitFailed(String),
80}
81
82#[derive(Debug, Error)]
84pub enum GlobError {
85 #[error("Invalid glob pattern '{pattern}': {reason}")]
87 InvalidPattern { pattern: String, reason: String },
88
89 #[error("Failed to build glob set: {0}")]
91 BuildFailed(String),
92}
93
94#[derive(Debug, Error)]
96pub enum GrepError {
97 #[error(transparent)]
99 Glob(#[from] GlobError),
100
101 #[error("Invalid regex pattern: {0}")]
103 InvalidRegex(String),
104
105 #[error("Search error: {0}")]
107 SearchFailed(String),
108
109 #[error("Search path does not exist: {0}")]
111 PathNotFound(String),
112}
113
114#[derive(Debug, Error)]
116pub enum AstGrepError {
117 #[error("Search path does not exist: {0}")]
119 PathNotFound(String),
120
121 #[error(transparent)]
123 Glob(#[from] GlobError),
124
125 #[error("Unsupported ast-grep language: {0}")]
127 UnsupportedLanguage(String),
128
129 #[error("Invalid ast-grep pattern: {0}")]
131 InvalidPattern(String),
132
133 #[error("Invalid regex for constraint '{name}': {reason}")]
135 InvalidConstraintRegex { name: String, reason: String },
136
137 #[error("Failed to read file '{path}': {reason}")]
139 ReadFailed { path: String, reason: String },
140
141 #[error("Search error: {0}")]
143 SearchFailed(String),
144}
145
146#[derive(Debug, Error)]
148pub enum FindError {
149 #[error("Search path does not exist: {0}")]
151 PathNotFound(String),
152
153 #[error("Invalid glob pattern '{pattern}': {reason}")]
155 InvalidGlobPattern { pattern: String, reason: String },
156
157 #[error("Failed to lock results")]
159 LockFailed,
160}
161
162#[derive(Debug, Error)]
164pub enum ListFilesError {
165 #[error("Failed to read directory: {0}")]
167 ReadDirFailed(String),
168
169 #[error("Failed to read entry: {0}")]
171 ReadEntryFailed(String),
172
173 #[error("Failed to read metadata: {0}")]
175 MetadataFailed(String),
176}
177
178#[derive(Debug, Error)]
180pub enum WebFetchError {
181 #[error("Invalid URL: {0}")]
183 InvalidUrl(String),
184
185 #[error("Request failed: {0}")]
187 RequestFailed(String),
188
189 #[error("Request timed out after {0}ms")]
191 Timeout(u64),
192
193 #[error("Response too large: {size} bytes exceeds limit of {limit} bytes")]
195 ResponseTooLarge { size: usize, limit: usize },
196
197 #[error("Failed to parse HTML: {0}")]
199 ParseFailed(String),
200}
201
202#[derive(Debug, Error)]
204pub enum WebSearchError {
205 #[error("Invalid search query: {0}")]
207 InvalidQuery(String),
208
209 #[error("API request failed: {0}")]
211 ApiError(String),
212
213 #[error("Rate limit exceeded: {0}")]
215 RateLimited(String),
216
217 #[error("Request timed out after {0}ms")]
219 Timeout(u64),
220
221 #[error("Configuration error: {0}")]
223 ConfigError(String),
224
225 #[error("Failed to parse API response: {0}")]
227 ParseError(String),
228}