n8n-io/n8n · warning · Error
File too large: ${stat.size} bytes (max ${MAX_FILE_SIZE} byt
Error message
File too large: ${stat.size} bytes (max ${MAX_FILE_SIZE} bytes). Use searchFiles for specific content. What it means
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.
Source
Thrown at packages/@n8n/computer-use/src/tools/filesystem/read-file.ts:42
});
export const readFileTool: ToolDefinition<typeof inputSchema> = {
name: 'read_file',
description:
'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.',
inputSchema,
annotations: { readOnlyHint: true },
async getAffectedResources({ filePath }, { dir }) {
return [
await buildFilesystemResource(dir, filePath, 'filesystemRead', `Read file: ${filePath}`),
];
},
async execute({ filePath, startLine, maxLines }, { dir }) {
const resolvedPath = await resolveReadablePath(dir, filePath);
const stat = await fs.stat(resolvedPath);
if (stat.size > MAX_FILE_SIZE) {
throw new Error(
`File too large: ${stat.size} bytes (max ${MAX_FILE_SIZE} bytes). Use searchFiles for specific content.`,
);
}
const fileContent = await fs.readFile(resolvedPath);
const buffer = Buffer.isBuffer(fileContent) ? fileContent : Buffer.from(fileContent);
const binaryType = detectSupportedBinaryFile(filePath);
if (binaryType) {
return buildBinaryResult(resolvedPath, buffer, binaryType);
}
if (isLikelyBinaryContent(buffer)) {
throw new Error('Unsupported binary file — only PNG, JPEG, GIF, WebP and PDF are readable');
}
return buildTextResult(filePath, buffer.toString('utf-8'), startLine, maxLines);
},View on GitHub (pinned to 5ac6606e81)
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
Example fix
// before (read_file fails on a large log):
await read_file({ filePath: 'logs/app.log' });
// after (search for specific content):
await search_files({ pattern: 'ERROR', glob: 'logs/app.log' }); Defensive patterns
Strategy: validation
Validate before calling
import * as fs from 'node:fs/promises';
import { MAX_FILE_SIZE } from './constants';
async function canReadFile(filePath: string): Promise<boolean> {
const stat = await fs.stat(filePath);
return stat.size <= MAX_FILE_SIZE;
}
// Before calling read_file:
if (!(await canReadFile(resolvedPath))) {
// Use search_files instead
await search_files({ pattern: 'keyword', glob: filePath });
} Type guard
function isReadFileTooLarge(e: unknown): boolean {
return e instanceof Error && e.message.startsWith('File too large:') && e.message.includes('Use searchFiles');
} Prevention
- 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
When it happens
Trigger: 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.
Common situations: Agent tries to read a large log file for debugging, a large data file for analysis, or a minified production bundle.
Related errors
- File too large: ${stat.size} bytes (max ${MAX_FILE_SIZE} byt
- oldString not found in file: ${filePath}
- Access denied: "${excludedSegment}" is excluded from filesys
- Unsupported binary file — only PNG, JPEG, GIF, WebP and PDF
- Pattern "${pattern}" escapes the base directory
AI-assisted analysis of n8n-io/n8n@5ac6606e81 (2026-08-12).
Data as JSON: /api/errors/dee13dee5d6647e7.
Report an issue: GitHub.