Skip to content

Commit c1dfded

Browse files
committed
Better error messages for diffs
1 parent 25da0b1 commit c1dfded

File tree

5 files changed

+226
-56
lines changed

5 files changed

+226
-56
lines changed

src/core/Cline.ts

Lines changed: 10 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1237,20 +1237,25 @@ export class Cline {
12371237
const originalContent = await fs.readFile(absolutePath, "utf-8")
12381238

12391239
// Apply the diff to the original content
1240-
let newContent = this.diffStrategy?.applyDiff(originalContent, diffContent) ?? false
1241-
if (newContent === false) {
1240+
const diffResult = this.diffStrategy?.applyDiff(originalContent, diffContent) ?? {
1241+
success: false,
1242+
error: "No diff strategy available"
1243+
}
1244+
if (!diffResult.success) {
12421245
this.consecutiveMistakeCount++
1243-
await this.say("error", `Unable to apply diff to file - contents are out of sync: ${absolutePath}`)
1244-
pushToolResult(`Error applying diff to file: ${absolutePath} - contents are out of sync. Try re-reading the relevant lines of the file and applying the diff again.`)
1246+
const errorDetails = diffResult.details ? `\n\nDetails:\n${JSON.stringify(diffResult.details, null, 2)}` : ''
1247+
await this.say("error", `Unable to apply diff to file: ${absolutePath}\n${diffResult.error}${errorDetails}`)
1248+
pushToolResult(`Error applying diff to file: ${absolutePath}\n${diffResult.error}${errorDetails}`)
12451249
break
12461250
}
1251+
const newContent = diffResult.content
12471252

12481253
this.consecutiveMistakeCount = 0
12491254

12501255
// Show diff view before asking for approval
12511256
this.diffViewProvider.editType = "modify"
12521257
await this.diffViewProvider.open(relPath);
1253-
await this.diffViewProvider.update(newContent, true);
1258+
await this.diffViewProvider.update(diffResult.content, true);
12541259
await this.diffViewProvider.scrollToFirstDiff();
12551260

12561261
const completeMessage = JSON.stringify({

0 commit comments

Comments
 (0)