From b2cae6c2fb3fde354ea7983bae3d67f1e143dcdc Mon Sep 17 00:00:00 2001 From: Saoud Rizwan <7799382+saoudrizwan@users.noreply.github.com> Date: Thu, 26 Dec 2024 12:55:00 -0800 Subject: [PATCH] Improve failed diff edit response --- src/core/Cline.ts | 8 +++++++- src/core/assistant-message/diff.ts | 2 +- 2 files changed, 8 insertions(+), 2 deletions(-) diff --git a/src/core/Cline.ts b/src/core/Cline.ts index dc41a7e973..5ba86fd7e6 100644 --- a/src/core/Cline.ts +++ b/src/core/Cline.ts @@ -1140,7 +1140,13 @@ export class Cline { } catch (error) { await this.say("diff_error", relPath) pushToolResult( - formatResponse.toolError(`Error writing file: ${(error as Error)?.message}`), + formatResponse.toolError( + `${(error as Error)?.message}\n\n` + + `This is likely due to character mismatches between the SEARCH block and the actual file.\n\n` + + `The file was reverted to its original state:\n\n` + + `\n${this.diffViewProvider.originalContent}\n\n\n` + + `Try again with a more precise SEARCH block.\n(If you keep running into this error, you may use the write_to_file tool as a workaround.)`, + ), ) await this.diffViewProvider.revertChanges() await this.diffViewProvider.reset() diff --git a/src/core/assistant-message/diff.ts b/src/core/assistant-message/diff.ts index 2ab5d9c5fb..d8f4056e41 100644 --- a/src/core/assistant-message/diff.ts +++ b/src/core/assistant-message/diff.ts @@ -297,7 +297,7 @@ export async function constructNewFileContent( ;[searchMatchIndex, searchEndIndex] = blockMatch } else { throw new Error( - `The SEARCH block:\n${currentSearchContent.trimEnd()}\n...does not match anything in the file.\nThis is likely due to differences in whitespace or line endings between the SEARCH block and the actual file. Try again with a more precise SEARCH block.\n(If you keep running into this error, you may use the write_to_file tool as a workaround.)`, + `The SEARCH block:\n${currentSearchContent.trimEnd()}\n...does not match anything in the file.`, ) } }