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.`, ) } }