diff --git a/src/core/Cline.ts b/src/core/Cline.ts index ccf2cffc2d..79dac08c45 100644 --- a/src/core/Cline.ts +++ b/src/core/Cline.ts @@ -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