{"record":{"id":"6d425759642cef2c","repo":"continuedev/continue","slug":"findandreplaceoldstringnotfound","errorCode":"FindAndReplaceOldStringNotFound","errorMessage":"Edit at index ${editIndex}: string not found in file: \"${oldString}\"","messagePattern":"Edit at index (.+?): string not found in file: \"(.+?)\"","errorType":"validation","errorClass":"ContinueError","httpStatus":null,"severity":"error","filePath":"core/edit/searchAndReplace/performReplace.ts","lineNumber":95,"sourceCode":"    if (line.startsWith(oldIndent)) {\n      return matchedIndent + line.slice(oldIndent.length);\n    }\n    return line;\n  });\n  return adjusted.join(\"\\n\");\n}\n\nexport function executeFindAndReplace(\n  fileContent: string,\n  oldString: string,\n  newString: string,\n  replaceAll: boolean,\n  editIndex = 0,\n): string {\n  const matches = findSearchMatches(fileContent, oldString);\n\n  if (matches.length === 0) {\n    throw new ContinueError(\n      ContinueErrorReason.FindAndReplaceOldStringNotFound,\n      `Edit at index ${editIndex}: string not found in file: \"${oldString}\"`,\n    );\n  }\n\n  if (replaceAll) {\n    // Apply replacements in reverse order to maintain correct positions\n    let result = fileContent;\n    for (let i = matches.length - 1; i >= 0; i--) {\n      const match = matches[i];\n      const adjustedNew = adjustReplacementIndentation(\n        result,\n        match,\n        oldString,\n        newString,\n      );\n      result =\n        result.substring(0, match.startIndex) +","sourceCodeStart":77,"sourceCodeEnd":113,"githubUrl":"https://github.com/continuedev/continue/blob/5522c6f44ca0ac3528b37244818fbfa39b5af470/core/edit/searchAndReplace/performReplace.ts#L77-L113","documentation":"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.","triggerScenarios":"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.","commonSituations":"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.","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"],"exampleFix":"// before\nawait findAndReplace({ filepath, old_string: \"function foo() {\", new_string: \"function bar() {\" });\n// after\nconst content = await readFile(filepath);\n// copy exact snippet from content, then:\nawait findAndReplace({ filepath, old_string: exactSnippet, new_string: exactSnippet.replace(\"foo\", \"bar\") });","handlingStrategy":"validation","validationCode":"const content = await readFile(filepath); if (!content.includes(oldString)) throw new Error('old_string not present; re-read file');","typeGuard":"const snippetExists = (content: string, s: string) => s === '' || content.includes(s);","tryCatchPattern":"catch (e) { if (e.message.includes('string not found in file')) { reReadFileAndRebuildEdit(); } else throw e; }","preventionTips":["Re-read the file right before editing","Copy snippets verbatim including indentation","Prefer short exact snippets over retyped ones"],"tags":["find-and-replace","not-found","string-match","edit"],"backgroundTag":"search-string-not-found","analyzedSha":"5522c6f44ca0ac3528b37244818fbfa39b5af470","analyzedAt":"2026-08-27T11:28:54.683Z","schemaVersion":2},"datasetVersion":"2026-08-27T13:17:12.746Z"}