mcp_servers/coding/
error.rs1use std::io;
7use thiserror::Error;
8
9use crate::lsp::error::LspError;
10use crate::workspace_paths::EmptyFilePathError;
11
12pub use crate::file_ops::FileError;
13
14#[doc = include_str!("../docs/coding_error.md")]
15#[derive(Debug, Error)]
16pub enum CodingError {
17 #[error(transparent)]
19 File(#[from] FileError),
20
21 #[error(transparent)]
23 Bash(#[from] BashError),
24
25 #[error(transparent)]
27 WebFetch(#[from] WebFetchError),
28
29 #[error(transparent)]
31 WebSearch(#[from] WebSearchError),
32
33 #[error(transparent)]
35 Lsp(#[from] LspError),
36
37 #[error("{0} is not configured")]
39 NotConfigured(&'static str),
40
41 #[error(transparent)]
43 EmptyFilePath(#[from] EmptyFilePathError),
44
45 #[error(
47 "Safety check failed: File '{0}' already exists. You must use read_file on it before overwriting. This prevents accidental data loss."
48 )]
49 NotReadBeforeOverwrite(String),
50
51 #[error(
53 "Safety check failed: You must use read_file on '{0}' before editing it. This ensures you understand the current file contents before making changes."
54 )]
55 NotReadBeforeEdit(String),
56
57 #[error("Failed to check existence of {path}: {source}")]
59 ExistsCheckFailed { path: String, source: io::Error },
60}
61
62impl rmcp::model::IntoContents for CodingError {
64 fn into_contents(self) -> Vec<rmcp::model::ContentBlock> {
65 vec![rmcp::model::ContentBlock::text(self.to_string())]
66 }
67}
68
69#[derive(Debug, Error)]
71pub enum BashError {
72 #[error("{0}")]
74 Forbidden(String),
75
76 #[error("Timeout cannot exceed 600000ms (10 minutes)")]
78 TimeoutTooLarge,
79
80 #[error("Failed to execute command '{command}': {reason}")]
82 SpawnFailed { command: String, reason: String },
83}
84
85#[derive(Debug, Clone, Error)]
87pub enum WebFetchError {
88 #[error("Invalid URL: {0}")]
90 InvalidUrl(#[source] url::ParseError),
91
92 #[error("Request failed: {0}")]
94 RequestFailed(String),
95
96 #[error("Request timed out after {0}ms")]
98 Timeout(u64),
99}
100
101#[derive(Debug, Clone, Error)]
103pub enum WebSearchError {
104 #[error("Invalid search query: {0}")]
106 InvalidQuery(String),
107
108 #[error("API request failed: {0}")]
110 ApiError(String),
111
112 #[error("Rate limit exceeded: {message}")]
114 RateLimited { message: String, retry_after: Option<std::time::Duration> },
115
116 #[error("Request timed out after {0}ms")]
118 Timeout(u64),
119
120 #[error("Configuration error: {0}")]
122 ConfigError(String),
123
124 #[error("Failed to parse API response: {0}")]
126 ParseError(String),
127}