Skip to content

Commit feb2fa8

Browse files
authored
Fix multi-file diff error handling and UI feedback (#4674)
fix: improve multi-file diff error handling and UI feedback - Fix nested array issue in multi-file-search-replace strategy - Consolidate diff error reporting to single message - Fix infinite spinner on single file diff failures
1 parent 7dd56d6 commit feb2fa8

File tree

2 files changed

+27
-1
lines changed

2 files changed

+27
-1
lines changed

src/core/diff/strategies/multi-file-search-replace.ts

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -410,7 +410,13 @@ Each file requires its own path, start_line, and diff elements.
410410
resultContent = singleResult.content
411411
successCount++
412412
} else {
413-
allFailParts.push(singleResult)
413+
// If singleResult has failParts, push those directly to avoid nesting
414+
if (singleResult.failParts && singleResult.failParts.length > 0) {
415+
allFailParts.push(...singleResult.failParts)
416+
} else {
417+
// Otherwise push the single result itself
418+
allFailParts.push(singleResult)
419+
}
414420
}
415421
}
416422

src/core/tools/multiApplyDiffTool.ts

Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -220,6 +220,7 @@ Original error: ${errorMessage}`
220220
try {
221221
// First validate all files and prepare for batch approval
222222
const operationsToApprove: OperationResult[] = []
223+
const allDiffErrors: string[] = [] // Collect all diff errors
223224

224225
for (const operation of operations) {
225226
const { path: relPath, diff: diffItems } = operation
@@ -435,6 +436,9 @@ Original error: ${errorMessage}`
435436
continue
436437
}
437438

439+
// Collect error for later reporting
440+
allDiffErrors.push(`${relPath} - Diff ${i + 1}: ${failPart.error}`)
441+
438442
const errorDetails = failPart.details ? JSON.stringify(failPart.details, null, 2) : ""
439443
formattedError += `<error_details>
440444
Diff ${i + 1} failed for file: ${relPath}
@@ -479,6 +483,17 @@ ${errorDetails ? `\nTechnical details:\n${errorDetails}\n` : ""}
479483
}
480484
cline.recordToolError("apply_diff", formattedError)
481485
results.push(formattedError)
486+
487+
// For single file operations, we need to send a complete message to stop the spinner
488+
if (operationsToApprove.length === 1) {
489+
const sharedMessageProps: ClineSayTool = {
490+
tool: "appliedDiff",
491+
path: getReadablePath(cline.cwd, relPath),
492+
diff: diffItems.map((item) => item.content).join("\n\n"),
493+
}
494+
// Send a complete message (partial: false) to update the UI and stop the spinner
495+
await cline.ask("tool", JSON.stringify(sharedMessageProps), false).catch(() => {})
496+
}
482497
}
483498
continue
484499
}
@@ -571,6 +586,11 @@ ${errorDetails ? `\nTechnical details:\n${errorDetails}\n` : ""}
571586
results.push(...filteredOperationErrors)
572587
}
573588

589+
// Report all diff errors at once if any
590+
if (allDiffErrors.length > 0) {
591+
await cline.say("diff_error", allDiffErrors.join("\n"))
592+
}
593+
574594
// Push the final result combining all operation results
575595
pushToolResult(results.join("\n\n"))
576596
return

0 commit comments

Comments
 (0)