From 5900629e6aed2be6a54c53f9e566cd6faef67d20 Mon Sep 17 00:00:00 2001 From: Saoud Rizwan <7799382+saoudrizwan@users.noreply.github.com> Date: Wed, 18 Dec 2024 14:58:37 -0800 Subject: [PATCH] Fix error message for when diff fails --- src/core/Cline.ts | 25 ++++++++++++++++++++----- 1 file changed, 20 insertions(+), 5 deletions(-) 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