{"record":{"id":"6c39b6ffca243a9c","repo":"n8n-io/n8n","slug":"oldstring-not-found-in-file-filepath","errorCode":null,"errorMessage":"oldString not found in file: ${filePath}","messagePattern":"oldString not found in file: (.+?)","errorType":"exception","errorClass":"Error","httpStatus":null,"severity":"error","filePath":"packages/@n8n/computer-use/src/tools/filesystem/edit-file.ts","lineNumber":41,"sourceCode":"\t\t\tawait buildFilesystemResource(dir, filePath, 'filesystemRead', `Read file: ${filePath}`),\n\t\t\tawait buildFilesystemResource(dir, filePath, 'filesystemWrite', `Edit file: ${filePath}`),\n\t\t];\n\t},\n\tasync execute({ filePath, oldString, newString }, { dir }) {\n\t\tconst resolvedReadablePath = await resolveReadablePath(dir, filePath);\n\t\tconst resolvedWritablePath = await resolveSafePath(dir, filePath);\n\n\t\tconst stat = await fs.stat(resolvedReadablePath);\n\t\tif (stat.size > MAX_FILE_SIZE) {\n\t\t\tthrow new Error(\n\t\t\t\t`File too large: ${stat.size} bytes (max ${MAX_FILE_SIZE} bytes). Use write_file to replace the entire content.`,\n\t\t\t);\n\t\t}\n\n\t\tconst content = await fs.readFile(resolvedReadablePath, 'utf-8');\n\n\t\tif (!content.includes(oldString)) {\n\t\t\tthrow new Error(`oldString not found in file: ${filePath}`);\n\t\t}\n\n\t\tawait fs.writeFile(resolvedWritablePath, content.replace(oldString, newString), 'utf-8');\n\n\t\treturn formatCallToolResult({ path: filePath });\n\t},\n};\n","sourceCodeStart":23,"sourceCodeEnd":49,"githubUrl":"https://github.com/n8n-io/n8n/blob/5ac6606e81f67bb9534255570cd4e86fd8101eee/packages/@n8n/computer-use/src/tools/filesystem/edit-file.ts#L23-L49","documentation":"Thrown by edit_file when oldString is not found as a substring of the file content. The file was successfully read and is under the size limit, but the exact text to replace does not exist in the file. This is a string-match failure, not a path or permission issue.","triggerScenarios":"The oldString has different whitespace or indentation than the file, the content was already modified by a prior edit, line endings differ (CRLF vs LF), the oldString was paraphrased rather than copied verbatim, or the target content is in a different file.","commonSituations":"AI agent generates oldString from memory without reading the file first, or the file changed between read and edit, or tabs vs spaces mismatch.","solutions":["Read the file first to copy the exact content for oldString","Use a shorter, unique substring of the target text as oldString","Check for whitespace, tab/space, and line-ending (CRLF/LF) differences","Use write_file to replace the entire file if the edit is large or the content is uncertain"],"exampleFix":"// before (oldString doesn't match exactly):\nawait edit_file({ filePath: 'src/app.ts', oldString: 'function main()', newString: 'function main(config)' });\n\n// after (read first, use exact text):\nconst content = await read_file({ filePath: 'src/app.ts' });\n// copy the exact line including whitespace\nawait edit_file({ filePath: 'src/app.ts', oldString: 'function main() {', newString: 'function main(config) {' });","handlingStrategy":"validation","validationCode":"import * as fs from 'node:fs/promises';\n\nasync function validateOldString(filePath: string, oldString: string): Promise<boolean> {\n  const content = await fs.readFile(filePath, 'utf-8');\n  return content.includes(oldString);\n}\n\n// Before calling edit_file:\nif (!(await validateOldString(resolvedPath, oldString))) {\n  throw new Error('oldString not found. Read the file first to get exact text.');\n}","typeGuard":"function isOldStringNotFound(e: unknown): boolean {\n  return e instanceof Error && e.message.startsWith('oldString not found in file:');\n}","tryCatchPattern":null,"preventionTips":["Always read the file before constructing oldString to get exact whitespace and content","Use the shortest unique substring of the target text as oldString","Be aware of tab vs space and CRLF vs LF differences when copying text"],"tags":["filesystem","validation","computer-use"],"backgroundTag":null,"analyzedSha":"5ac6606e81f67bb9534255570cd4e86fd8101eee","analyzedAt":"2026-08-12T05:26:35.080Z","schemaVersion":2},"datasetVersion":"2026-08-12T13:17:24.610Z"}