continuedev/continue · error · ContinueError
FindAndReplaceOldStringNotFound
FindAndReplaceOldStringNotFound
Error message
Edit at index ${editIndex}: string not found in file: "${oldString}" What it means
Thrown by executeFindAndReplace when findSearchMatches locates zero occurrences of old_string in the target file content. The library refuses to 'replace' text that does not exist so failures surface immediately rather than silently succeeding.
Source
Thrown at core/edit/searchAndReplace/performReplace.ts:95
if (line.startsWith(oldIndent)) {
return matchedIndent + line.slice(oldIndent.length);
}
return line;
});
return adjusted.join("\n");
}
export function executeFindAndReplace(
fileContent: string,
oldString: string,
newString: string,
replaceAll: boolean,
editIndex = 0,
): string {
const matches = findSearchMatches(fileContent, oldString);
if (matches.length === 0) {
throw new ContinueError(
ContinueErrorReason.FindAndReplaceOldStringNotFound,
`Edit at index ${editIndex}: string not found in file: "${oldString}"`,
);
}
if (replaceAll) {
// Apply replacements in reverse order to maintain correct positions
let result = fileContent;
for (let i = matches.length - 1; i >= 0; i--) {
const match = matches[i];
const adjustedNew = adjustReplacementIndentation(
result,
match,
oldString,
newString,
);
result =
result.substring(0, match.startIndex) +View on GitHub (pinned to 5522c6f44c)
Solutions
- Re-read the file and copy old_string exactly, including indentation and line endings
- Trim or expand the old_string to a smaller unique snippet you can verify exists
- Verify you are editing the resolved path returned by filepath validation, not a stale relative path
- If the file may have changed, re-fetch content and rebuild the edit
Example fix
// before
await findAndReplace({ filepath, old_string: "function foo() {", new_string: "function bar() {" });
// after
const content = await readFile(filepath);
// copy exact snippet from content, then:
await findAndReplace({ filepath, old_string: exactSnippet, new_string: exactSnippet.replace("foo", "bar") }); Defensive patterns
Strategy: validation
Validate before calling
const content = await readFile(filepath); if (!content.includes(oldString)) throw new Error('old_string not present; re-read file'); Type guard
const snippetExists = (content: string, s: string) => s === '' || content.includes(s);
Try / catch
catch (e) { if (e.message.includes('string not found in file')) { reReadFileAndRebuildEdit(); } else throw e; } Prevention
- Re-read the file right before editing
- Copy snippets verbatim including indentation
- Prefer short exact snippets over retyped ones
When it happens
Trigger: The old_string text is not present verbatim: whitespace/indentation mismatch, tabs vs spaces, the file changed since the string was read, or a typo in the literal.
Common situations: LLM edits based on stale file contents (file modified between read and edit); trailing whitespace differences; line-ending differences (CRLF vs LF); wrong file path pointing to a similar file.
Related errors
- FindAndReplaceIdenticalOldAndNewStrings
- FindAndReplaceMultipleOccurrences
- Lazy apply not supported for model ${llm.model}
- Hunk could not be applied cleanly to source code.
- Token limit reached. File/range likely too large for this ed
AI-assisted analysis of continuedev/continue@5522c6f44c (2026-08-27).
Data as JSON: /api/errors/6d425759642cef2c.
Report an issue: GitHub.