{"record":{"id":"5476cae5d0a99377","repo":"n8n-io/n8n","slug":"no-exact-match-found-for-str-replace-the-old-str","errorCode":null,"errorMessage":"No exact match found for str_replace. The old_str content was not found in the file.","messagePattern":"No exact match found for str_replace\\. The old_str content was not found in the file\\.","errorType":"exception","errorClass":"NoMatchFoundError","httpStatus":null,"severity":"error","filePath":"packages/@n8n/ai-utilities/src/utils/text-editor.ts","lineNumber":377,"sourceCode":"\n\tprivate handleStrReplace(command: StrReplaceCommand): string {\n\t\tif (this.text === null) {\n\t\t\tthrow this.createFileNotFoundError();\n\t\t}\n\n\t\tconst { old_str, new_str } = command;\n\t\tconst count = this.countOccurrences(this.text, old_str);\n\n\t\tif (count === 0) {\n\t\t\tconst normalized = old_str.endsWith('\\n') ? old_str.slice(0, -1) : old_str + '\\n';\n\t\t\tconst normalizedCount = this.countOccurrences(this.text, normalized);\n\t\t\tif (normalizedCount === 1) {\n\t\t\t\tthis.text = this.text.replace(normalized, this.escapeReplacement(new_str));\n\t\t\t\treturn 'Edit applied successfully.';\n\t\t\t}\n\n\t\t\tconst context = findDivergenceContext(this.text, old_str);\n\t\t\tthrow new NoMatchFoundError(old_str, context);\n\t\t}\n\n\t\tif (count > 1) {\n\t\t\tthrow new MultipleMatchesError(count);\n\t\t}\n\n\t\tthis.text = this.text.replace(old_str, this.escapeReplacement(new_str));\n\t\treturn 'Edit applied successfully.';\n\t}\n\n\tprivate handleInsert(command: InsertCommand): string {\n\t\tif (this.text === null) {\n\t\t\tthrow this.createFileNotFoundError();\n\t\t}\n\n\t\tconst { insert_line, insert_text } = command;\n\t\tconst lines = this.text.split('\\n');\n","sourceCodeStart":359,"sourceCodeEnd":395,"githubUrl":"https://github.com/n8n-io/n8n/blob/5ac6606e81f67bb9534255570cd4e86fd8101eee/packages/@n8n/ai-utilities/src/utils/text-editor.ts#L359-L395","documentation":"Edit failure (NoMatchFoundError) from the text editor's handleStrReplace. It fires when old_str occurs zero times in the file, and also zero times after trailing-newline normalization. This is the strict-failure path: unlike the normalized single-match case, which auto-applies, the tool cannot guess the intended text and reports no match so the caller can revise old_str.","triggerScenarios":"Thrown at packages/@n8n/ai-utilities/src/utils/text-editor.ts:377 when the library encounters an invalid state.","commonSituations":"See trigger scenarios.","solutions":["Read the file with the view command first and copy old_str exactly from the current content, including whitespace and indentation.","The error context shows the closest match and where it diverges — align old_str with that region.","Note the tool already retries once with normalized trailing-newline handling; if it still fails, the text really differs."],"exampleFix":null,"handlingStrategy":"validation","validationCode":null,"typeGuard":null,"tryCatchPattern":null,"preventionTips":[],"tags":[],"backgroundTag":null,"analyzedSha":"5ac6606e81f67bb9534255570cd4e86fd8101eee","analyzedAt":"2026-08-12T05:26:35.080Z","contentChangedAt":"2026-08-12T05:26:35.080Z","schemaVersion":2},"datasetVersion":"2026-09-23T08:17:48.524Z"}