{"record":{"id":"dee13dee5d6647e7","repo":"n8n-io/n8n","slug":"file-too-large-stat-size-bytes-max-max-file-dee13d","errorCode":null,"errorMessage":"File too large: ${stat.size} bytes (max ${MAX_FILE_SIZE} bytes). Use searchFiles for specific content.","messagePattern":"File too large: (.+?) bytes \\(max (.+?) bytes\\)\\. Use searchFiles for specific content\\.","errorType":"exception","errorClass":"Error","httpStatus":null,"severity":"warning","filePath":"packages/@n8n/computer-use/src/tools/filesystem/read-file.ts","lineNumber":42,"sourceCode":"});\n\nexport const readFileTool: ToolDefinition<typeof inputSchema> = {\n\tname: 'read_file',\n\tdescription:\n\t\t'Read a file. Text is returned line-by-line; supported binaries (PNG, JPEG, GIF, WebP, PDF) are returned as base64 content the model can consume directly.',\n\tinputSchema,\n\tannotations: { readOnlyHint: true },\n\tasync getAffectedResources({ filePath }, { dir }) {\n\t\treturn [\n\t\t\tawait buildFilesystemResource(dir, filePath, 'filesystemRead', `Read file: ${filePath}`),\n\t\t];\n\t},\n\tasync execute({ filePath, startLine, maxLines }, { dir }) {\n\t\tconst resolvedPath = await resolveReadablePath(dir, filePath);\n\n\t\tconst stat = await fs.stat(resolvedPath);\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 searchFiles for specific content.`,\n\t\t\t);\n\t\t}\n\n\t\tconst fileContent = await fs.readFile(resolvedPath);\n\t\tconst buffer = Buffer.isBuffer(fileContent) ? fileContent : Buffer.from(fileContent);\n\n\t\tconst binaryType = detectSupportedBinaryFile(filePath);\n\t\tif (binaryType) {\n\t\t\treturn buildBinaryResult(resolvedPath, buffer, binaryType);\n\t\t}\n\n\t\tif (isLikelyBinaryContent(buffer)) {\n\t\t\tthrow new Error('Unsupported binary file — only PNG, JPEG, GIF, WebP and PDF are readable');\n\t\t}\n\n\t\treturn buildTextResult(filePath, buffer.toString('utf-8'), startLine, maxLines);\n\t},","sourceCodeStart":24,"sourceCodeEnd":60,"githubUrl":"https://github.com/n8n-io/n8n/blob/5ac6606e81f67bb9534255570cd4e86fd8101eee/packages/@n8n/computer-use/src/tools/filesystem/read-file.ts#L24-L60","documentation":"Thrown by the read_file tool when the target file's size exceeds MAX_FILE_SIZE (1 MB). The guard runs after path resolution but before reading the file content into memory. The message suggests using search_files for specific content rather than loading the whole file.","triggerScenarios":"Calling read_file on a file larger than 1 MB — a large log file, data export (JSON/CSV), minified JavaScript bundle, or large generated source file.","commonSituations":"Agent tries to read a large log file for debugging, a large data file for analysis, or a minified production bundle.","solutions":["Use search_files to find specific content with a regex pattern instead of reading the whole file","Use list_files to understand the directory structure first, then read only the relevant smaller files","If line-specific content is needed, use shell tools (grep, sed) to extract the relevant lines"],"exampleFix":"// before (read_file fails on a large log):\nawait read_file({ filePath: 'logs/app.log' });\n\n// after (search for specific content):\nawait search_files({ pattern: 'ERROR', glob: 'logs/app.log' });","handlingStrategy":"validation","validationCode":"import * as fs from 'node:fs/promises';\nimport { MAX_FILE_SIZE } from './constants';\n\nasync function canReadFile(filePath: string): Promise<boolean> {\n  const stat = await fs.stat(filePath);\n  return stat.size <= MAX_FILE_SIZE;\n}\n\n// Before calling read_file:\nif (!(await canReadFile(resolvedPath))) {\n  // Use search_files instead\n  await search_files({ pattern: 'keyword', glob: filePath });\n}","typeGuard":"function isReadFileTooLarge(e: unknown): boolean {\n  return e instanceof Error && e.message.startsWith('File too large:') && e.message.includes('Use searchFiles');\n}","tryCatchPattern":null,"preventionTips":["Check file size with fs.stat before calling read_file on unknown files","Use search_files for large files to find specific content with regex patterns","Use list_files to explore directory structure and identify smaller relevant files"],"tags":["filesystem","validation","computer-use"],"backgroundTag":null,"analyzedSha":"5ac6606e81f67bb9534255570cd4e86fd8101eee","analyzedAt":"2026-08-12T05:26:35.080Z","schemaVersion":2},"datasetVersion":"2026-08-12T18:17:37.767Z"}