{"record":{"id":"681003d07619433f","repo":"continuedev/continue","slug":"findandreplacemultipleoccurrences","errorCode":"FindAndReplaceMultipleOccurrences","errorMessage":"Edit at index ${editIndex}: String \"${oldString}\" appears ${matches.length} times in the file. Either provide a more specific string with surrounding context to make it unique, or use replace_all=true to replace all occurrences.","messagePattern":"Edit at index (.+?): String \"(.+?)\" appears (.+?) times in the file\\. Either provide a more specific string with surrounding context to make it unique, or use replace_all=true to replace all occurrences\\.","errorType":"validation","errorClass":"ContinueError","httpStatus":null,"severity":"error","filePath":"core/edit/searchAndReplace/performReplace.ts","lineNumber":121,"sourceCode":"    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) +\n        adjustedNew +\n        result.substring(match.endIndex);\n    }\n    return result;\n  } else {\n    // For single replacement, check for multiple matches first\n    if (matches.length > 1) {\n      throw new ContinueError(\n        ContinueErrorReason.FindAndReplaceMultipleOccurrences,\n        `Edit at index ${editIndex}: String \"${oldString}\" appears ${matches.length} times in the file. Either provide a more specific string with surrounding context to make it unique, or use replace_all=true to replace all occurrences.`,\n      );\n    }\n\n    // Apply single replacement\n    const match = matches[0];\n    const adjustedNew = adjustReplacementIndentation(\n      fileContent,\n      match,\n      oldString,\n      newString,\n    );\n    return (\n      fileContent.substring(0, match.startIndex) +\n      adjustedNew +\n      fileContent.substring(match.endIndex)\n    );","sourceCodeStart":103,"sourceCodeEnd":139,"githubUrl":"https://github.com/continuedev/continue/blob/5522c6f44ca0ac3528b37244818fbfa39b5af470/core/edit/searchAndReplace/performReplace.ts#L103-L139","documentation":"Thrown when old_string matches more than once and replace_all is not enabled. Because a non-replace_all edit must be unambiguous, the library reports the match count and asks for either a more specific string or replace_all=true.","triggerScenarios":"old_string matches 2+ locations in the file, e.g. replacing a common identifier like \"const x\" that appears multiple times, without replace_all.","commonSituations":"Replacing short/common tokens (import lines, repeated JSX patterns, variable names); refactoring duplicated code blocks; LLMs quoting only a function signature that appears in both declaration and calls.","solutions":["Add surrounding context lines to old_string so it matches exactly once","Set replace_all: true if you really intend to replace every occurrence","Use the reported match count to iterate: narrow with preceding/following lines until unique"],"exampleFix":"// before\n{ old_string: \"return null;\", new_string: \"return undefined;\" }\n// after\n{ old_string: \"function findUser(id) {\\n  return null;\", new_string: \"function findUser(id) {\\n  return undefined;\" }","handlingStrategy":"validation","validationCode":"const n = fileContent.split(oldString).length - 1; if (n > 1 && !replaceAll) throw new Error(`ambiguous: ${n} matches`);","typeGuard":"const isUnique = (content: string, s: string) => content.indexOf(s) === content.lastIndexOf(s);","tryCatchPattern":"catch (e) { if (e.message.includes('appears') && e.message.includes('times')) { retry with replace_all or longer context; } else throw e; }","preventionTips":["Include neighboring lines in old_string","Pre-check uniqueness with indexOf/lastIndexOf","Set replace_all deliberately when multi-replace is intended"],"tags":["find-and-replace","ambiguous-match","multiple-occurrences","edit"],"backgroundTag":"ambiguous-search-match","analyzedSha":"5522c6f44ca0ac3528b37244818fbfa39b5af470","analyzedAt":"2026-08-27T11:28:54.683Z","schemaVersion":2},"datasetVersion":"2026-08-27T13:17:12.746Z"}