{"record":{"id":"b1f861d946ce6c1e","repo":"continuedev/continue","slug":"findandreplacemissingoldstring","errorCode":"FindAndReplaceMissingOldString","errorMessage":"${context}string old_string is required","messagePattern":"(.+?)string old_string is required","errorType":"validation","errorClass":"ContinueError","httpStatus":null,"severity":"error","filePath":"core/edit/searchAndReplace/findAndReplaceUtils.ts","lineNumber":18,"sourceCode":"import { ContinueError, ContinueErrorReason } from \"../../util/errors\";\n\nexport const FOUND_MULTIPLE_FIND_STRINGS_ERROR =\n  \"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 * Validates a single edit operation\n */\nexport function validateSingleEdit(\n  oldString: unknown,\n  newString: unknown,\n  replaceAll: unknown,\n  index?: number,\n): { oldString: string; newString: string; replaceAll?: boolean } {\n  const context = index !== undefined ? `edit at index ${index}: ` : \"\";\n\n  if (oldString === undefined || typeof oldString !== \"string\") {\n    throw new ContinueError(\n      ContinueErrorReason.FindAndReplaceMissingOldString,\n      `${context}string old_string is required`,\n    );\n  }\n  if (newString === undefined || typeof newString !== \"string\") {\n    throw new ContinueError(\n      ContinueErrorReason.FindAndReplaceMissingNewString,\n      `${context}string new_string is required`,\n    );\n  }\n  if (oldString === newString) {\n    throw new ContinueError(\n      ContinueErrorReason.FindAndReplaceIdenticalOldAndNewStrings,\n      `${context}old_string and new_string must be different`,\n    );\n  }\n  if (replaceAll !== undefined && typeof replaceAll !== \"boolean\") {\n    throw new ContinueError(","sourceCodeStart":1,"sourceCodeEnd":36,"githubUrl":"https://github.com/continuedev/continue/blob/5522c6f44ca0ac3528b37244818fbfa39b5af470/core/edit/searchAndReplace/findAndReplaceUtils.ts#L1-L36","documentation":"validateSingleEdit enforces the search/replace edit schema: old_string must be present and a string. Missing or non-string old_string throws ContinueError with code FindAndReplaceMissingOldString (message prefixed with the multi-edit index when applicable).","triggerScenarios":"Passing an edit object without oldString, or with oldString set to null/number (e.g. from unvalidated JSON or LLM output).","commonSituations":"LLM emits {new_string: ...} without old_string; user scripts build edit payloads from dynamic data where the field can be undefined; schema drift between versions.","solutions":["Validate edit payloads before calling apply (required string oldString)","Fix the producer (prompt/tool schema) to always include old_string","Log the index from the message to locate the offending edit in a multi-edit"],"exampleFix":"// before\napplyEdits([{ newString: \"x\" }]);\n// after\napplyEdits([{ oldString: \"y\", newString: \"x\" }]);","handlingStrategy":"type-guard","validationCode":"edits.every(e => typeof e?.oldString === 'string' && typeof e?.newString === 'string') || failFast();","typeGuard":"const isValidEdit = (e: unknown): e is { oldString: string; newString: string; replaceAll?: boolean } =>\n  typeof (e as any)?.oldString === 'string' && typeof (e as any)?.newString === 'string';","tryCatchPattern":"catch (e) { if (e instanceof ContinueError && e.code === 'FindAndReplaceMissingOldString') { reportEditIndex(e.message); } }","preventionTips":["Schema-validate LLM/tool edit payloads before applying","Use typed wrappers around raw JSON edit objects"],"tags":["validation","edit","schema","llm-output"],"backgroundTag":"schema-validation-failed","analyzedSha":"5522c6f44ca0ac3528b37244818fbfa39b5af470","analyzedAt":"2026-08-27T11:28:54.683Z","schemaVersion":2},"datasetVersion":"2026-08-27T13:17:12.746Z"}