Fix error message for when diff fails

This commit is contained in:
Saoud Rizwan 2024-12-18 14:58:37 -08:00
parent 7fa399c6af
commit 5900629e6a

View file

@ -1106,11 +1106,26 @@ export class Cline {
// Construct newContent from diff
let newContent: string
if (diff) {
newContent = await constructNewFileContent(
diff,
this.diffViewProvider.originalContent || "",
!block.partial,
)
try {
newContent = await constructNewFileContent(
diff,
this.diffViewProvider.originalContent || "",
!block.partial,
)
} catch (error) {
await this.say(
"error",
`Failed to apply changes to ${relPath}. The model's diff instructions could not be processed correctly. This usually happens when the search patterns don't match the file content exactly.`,
)
pushToolResult(
formatResponse.toolError(
`Error writing file: ${JSON.stringify(serializeError(error))}`,
),
)
await this.diffViewProvider.revertChanges()
await this.diffViewProvider.reset()
break
}
} else if (content) {
newContent = content