From 1afef7d61da274c67a1bbb304cdce8be35cbcbeb Mon Sep 17 00:00:00 2001 From: Roo Code Date: Sat, 8 Nov 2025 06:46:14 +0000 Subject: [PATCH] fix: improve apply_diff error messages with clear examples - Added applyDiffMissingParamError function to provide tool-specific error messages - Shows relevant examples for both legacy and new apply_diff formats - Includes helpful hints about exact content matching and using read_file tool - Addresses issue #9113 for better error clarity when apply_diff validation fails --- src/core/prompts/responses.ts | 58 ++++++++++++++++++++++++++++ src/core/tools/multiApplyDiffTool.ts | 15 +------ 2 files changed, 60 insertions(+), 13 deletions(-) diff --git a/src/core/prompts/responses.ts b/src/core/prompts/responses.ts index 21703684b8..e25b99d5f7 100644 --- a/src/core/prompts/responses.ts +++ b/src/core/prompts/responses.ts @@ -36,6 +36,64 @@ Otherwise, if you have not completed the task and do not need additional informa missingToolParameterError: (paramName: string) => `Missing value for required parameter '${paramName}'. Please retry with complete response.\n\n${toolUseInstructionsReminder}`, + applyDiffMissingParamError: (isLegacyMode: boolean) => { + const errorType = isLegacyMode + ? "legacy 'path' and 'diff' (must be valid and non-empty)" + : "args (must contain at least one valid file element)" + + const example = isLegacyMode + ? `# Example for apply_diff (legacy mode): + + +src/example.js + +<<<<<<< SEARCH +:start_line:10 +------- +const oldFunction = () => { + return "old value"; +}; +======= +const newFunction = () => { + return "new value"; +}; +>>>>>>> REPLACE + +` + : `# Example for apply_diff: + + + + + src/example.js + + +<<<<<<< SEARCH +:start_line:10 +------- +const oldFunction = () => { + return "old value"; +}; +======= +const newFunction = () => { + return "new value"; +}; +>>>>>>> REPLACE + + 10 + + + +` + + return `Missing value for required parameter '${errorType}'. Please retry with complete response. + +${example} + +Note: The search content must match the file content EXACTLY, including whitespace and indentation. +Use the read_file tool first if you need to verify the current file content.` + }, + lineCountTruncationError: (actualLineCount: number, isNewFile: boolean, diffStrategyEnabled: boolean = false) => { const truncationMessage = `Note: Your response may have been truncated because it exceeded your output limit. You wrote ${actualLineCount} lines of content, but the line_count parameter was either missing or not included in your response.` diff --git a/src/core/tools/multiApplyDiffTool.ts b/src/core/tools/multiApplyDiffTool.ts index 08bce08ede..0450f31833 100644 --- a/src/core/tools/multiApplyDiffTool.ts +++ b/src/core/tools/multiApplyDiffTool.ts @@ -192,11 +192,7 @@ Original error: ${errorMessage}` // Neither new XML args nor old path/diff params are sufficient cline.consecutiveMistakeCount++ cline.recordToolError("apply_diff") - const errorMsg = await cline.sayAndCreateMissingParamError( - "apply_diff", - "args (or legacy 'path' and 'diff' parameters)", - ) - pushToolResult(errorMsg) + pushToolResult(formatResponse.applyDiffMissingParamError(false)) cline.processQueuedMessages() return } @@ -205,14 +201,7 @@ Original error: ${errorMessage}` if (Object.keys(operationsMap).length === 0) { cline.consecutiveMistakeCount++ cline.recordToolError("apply_diff") - pushToolResult( - await cline.sayAndCreateMissingParamError( - "apply_diff", - usingLegacyParams - ? "legacy 'path' and 'diff' (must be valid and non-empty)" - : "args (must contain at least one valid file element)", - ), - ) + pushToolResult(formatResponse.applyDiffMissingParamError(usingLegacyParams)) cline.processQueuedMessages() return }