fix: restore AppError::Internal for AST parser error, keeping BadRequest for JSON schema validation
This commit is contained in:
1 parent
39528411f4
commit
de060c4db4
10 files changed
+57
-57
No files matched your search
@@ -41,7 +41,7 @@ impl McpTool for ReadFileSkeletonHandler {
|
||||
|
||||
async fn execute(&self, args: Value, _state: Arc<MemoryState>) -> crate::error::Result<String> {
|
||||
let tool_args: ReadFileSkeletonTool =
|
||||
serde_json::from_value(args).map_err(|e| e.to_string())?;
|
||||
serde_json::from_value(args).map_err(|e| crate::error::AppError::BadRequest(format!("Schema validation failed. Your JSON arguments do not match the expected tool schema: {}", e)))?;
|
||||
|
||||
let file_path = tool_args.file_path.clone();
|
||||
validate_safe_path(&file_path)?;
|
||||
@@ -202,7 +202,7 @@ impl McpTool for ReplaceAstNodeHandler {
|
||||
|
||||
async fn execute(&self, args: Value, _state: Arc<MemoryState>) -> crate::error::Result<String> {
|
||||
let tool_args: ReplaceAstNodeTool =
|
||||
serde_json::from_value(args).map_err(|e| e.to_string())?;
|
||||
serde_json::from_value(args).map_err(|e| crate::error::AppError::BadRequest(format!("Schema validation failed. Your JSON arguments do not match the expected tool schema: {}", e)))?;
|
||||
|
||||
let file_path = tool_args.file_path.clone();
|
||||
validate_safe_path(&file_path)?;
|
||||
@@ -237,7 +237,7 @@ impl McpTool for ReplaceAstNodeHandler {
|
||||
|
||||
parser
|
||||
.set_language(&language.into())
|
||||
.map_err(|e| e.to_string())?;
|
||||
.map_err(|e| crate::error::AppError::Internal(e.to_string()))?;
|
||||
let tree = parser.parse(&code, None).ok_or_else(|| {
|
||||
crate::error::AppError::Internal("Failed to parse code".to_string())
|
||||
})?;
|
||||
@@ -342,7 +342,7 @@ impl McpTool for ReplaceAstNodeHandler {
|
||||
.unwrap_or_else(|| std::path::Path::new("."));
|
||||
let temp_file_path =
|
||||
parent_dir.join(format!(".tmp_ast_{}.tmp", uuid::Uuid::new_v4()));
|
||||
std::fs::write(&temp_file_path, new_file_content).map_err(|e| e.to_string())?;
|
||||
std::fs::write(&temp_file_path, new_file_content).map_err(|e| crate::error::AppError::Internal(format!("Failed to write temporary file: {}", e)))?;
|
||||
if let Err(e) = std::fs::rename(&temp_file_path, &target_path) {
|
||||
// On Windows, std::fs::rename fails if the target file already exists.
|
||||
// Fall back to copy-and-remove to ensure atomic-like overwrite behavior.
|
||||
@@ -473,7 +473,7 @@ impl McpTool for FindSymbolReferencesHandler {
|
||||
|
||||
async fn execute(&self, args: Value, state: Arc<MemoryState>) -> crate::error::Result<String> {
|
||||
let req: crate::tools::FindSymbolReferencesTool =
|
||||
serde_json::from_value(args).map_err(|e| e.to_string())?;
|
||||
serde_json::from_value(args).map_err(|e| crate::error::AppError::BadRequest(format!("Schema validation failed. Your JSON arguments do not match the expected tool schema: {}", e)))?;
|
||||
let limit = req.limit.unwrap_or(10);
|
||||
let target_sym = req.symbol.clone();
|
||||
|
||||
@@ -527,7 +527,7 @@ impl McpTool for GetCallersHandler {
|
||||
|
||||
async fn execute(&self, args: Value, state: Arc<MemoryState>) -> crate::error::Result<String> {
|
||||
let req: crate::tools::GetCallersTool =
|
||||
serde_json::from_value(args).map_err(|e| e.to_string())?;
|
||||
serde_json::from_value(args).map_err(|e| crate::error::AppError::BadRequest(format!("Schema validation failed. Your JSON arguments do not match the expected tool schema: {}", e)))?;
|
||||
let limit = req.limit.unwrap_or(10);
|
||||
let target_fn = req.function_name.clone();
|
||||
let call_pattern = format!("{}(", target_fn);
|
||||
@@ -583,7 +583,7 @@ impl McpTool for AnalyzeImpactHandler {
|
||||
|
||||
async fn execute(&self, args: Value, state: Arc<MemoryState>) -> crate::error::Result<String> {
|
||||
let req: crate::tools::AnalyzeImpactTool =
|
||||
serde_json::from_value(args).map_err(|e| e.to_string())?;
|
||||
serde_json::from_value(args).map_err(|e| crate::error::AppError::BadRequest(format!("Schema validation failed. Your JSON arguments do not match the expected tool schema: {}", e)))?;
|
||||
let sym = req.target_symbol.clone();
|
||||
|
||||
let mut callers = Vec::new();
|
||||
|
||||
Reference in new issue
Block a user