diff --git a/src/filesystem/__tests__/lib.test.ts b/src/filesystem/__tests__/lib.test.ts index e0ae61224f..4c88580ee2 100644 --- a/src/filesystem/__tests__/lib.test.ts +++ b/src/filesystem/__tests__/lib.test.ts @@ -516,7 +516,9 @@ describe('Lib Functions', () => { ]; await expect(applyFileEdits('/test/file.txt', edits, false)) - .rejects.toThrow('Could not find exact match for edit'); + .rejects.toThrow( + 'Use read_file to inspect the exact current content, then retry with oldText copied from the file' + ); }); it('handles complex multi-line edits with indentation', async () => { diff --git a/src/filesystem/lib.ts b/src/filesystem/lib.ts index ce4af9f38a..ee58c8605a 100644 --- a/src/filesystem/lib.ts +++ b/src/filesystem/lib.ts @@ -248,7 +248,11 @@ export async function applyFileEdits( } if (!matchFound) { - throw new Error(`Could not find exact match for edit:\n${edit.oldText}`); + throw new Error( + `Could not find exact match for edit:\n${edit.oldText}\n\n` + + `This usually means the requested text differs from the file content in whitespace, indentation, or line endings. ` + + `Use read_file to inspect the exact current content, then retry with oldText copied from the file.` + ); } }