different-ai/openwork · error · Error
FILE_TOO_LARGE
FILE_TOO_LARGE
Error message
File exceeds the configured read limit
What it means
Before opening the file, readBoundedRegularTextFile compares the lstat size against options.maxBytes and throws an Error with code FILE_TOO_LARGE when the on-disk size already exceeds the caller's memory budget. This is the pre-open half of the size guard; a second check runs after open.
Source
Thrown at apps/server/src/jsonc.ts:63
* Read a small diagnostics input without following symlinks or opening a FIFO
* in blocking mode. The size is checked both before and while reading so a
* file that grows after inspection cannot exceed the caller's memory budget.
*/
export async function readBoundedRegularTextFile(
path: string,
options: { maxBytes: number; signal?: AbortSignal },
): Promise<string> {
if (!Number.isSafeInteger(options.maxBytes) || options.maxBytes < 0) {
throw new RangeError("maxBytes must be a non-negative safe integer");
}
throwIfAborted(options.signal);
const pathMetadata = await lstat(path);
throwIfAborted(options.signal);
if (!pathMetadata.isFile()) {
throw fileReadError("NOT_REGULAR_FILE", "Expected a regular file");
}
if (pathMetadata.size > options.maxBytes) {
throw fileReadError("FILE_TOO_LARGE", "File exceeds the configured read limit");
}
const nonBlockingFlags = process.platform === "win32"
? 0
: constants.O_NONBLOCK | constants.O_NOFOLLOW;
const handle = await open(path, constants.O_RDONLY | nonBlockingFlags);
try {
const openedMetadata = await handle.stat();
throwIfAborted(options.signal);
if (!openedMetadata.isFile()) {
throw fileReadError("NOT_REGULAR_FILE", "Expected a regular file");
}
if (openedMetadata.size > options.maxBytes) {
throw fileReadError("FILE_TOO_LARGE", "File exceeds the configured read limit");
}
const chunks: Buffer[] = [];
let totalBytes = 0;View on GitHub (pinned to 2b7df46e8a)
Solutions
- Raise options.maxBytes to a value appropriate for the intended file.
- Trim, rotate, or remove the oversized file before reading.
- Stream/chunk the file yourself if it legitimately exceeds the budget.
- Verify the path — you may be reading the wrong, much larger file.
Example fix
// before
const raw = await readJsoncFile(bigPath, { maxBytes: 64 * 1024 }); // 2MB file -> FILE_TOO_LARGE
// after
const st = await fs.stat(bigPath);
const raw = await readJsoncFile(bigPath, { maxBytes: Math.max(64 * 1024, st.size + 1024) }); Defensive patterns
Strategy: validation
Validate before calling
const st = await fs.stat(path);
const MAX = 64 * 1024;
if (st.size > MAX) throw new Error(`${path} is ${st.size} bytes, limit ${MAX}`); Type guard
null
Try / catch
try {
return await readJsoncFile(path, { maxBytes: MAX });
} catch (e) {
if ((e as NodeJS.ErrnoException).code === "FILE_TOO_LARGE") return readBoundedTail(path, MAX);
throw e;
} Prevention
- Match maxBytes to the expected file class (configs vs exports).
- Rotate or trim files that grow unbounded.
- Stat before read and fail fast with a size report.
- Never point bounded diagnostics readers at arbitrary large data files.
When it happens
Trigger: Calling readJsoncFile/raw on a regular file whose lstat size is greater than options.maxBytes (e.g. reading a multi-GB JSONC with the small diagnostics default limit).
Common situations: A log or config file grew far beyond expected size; the diagnostics reader was pointed at a large data export; maxBytes was set too small for the class of file being read.
Related errors
- NOT_REGULAR_FILE
- ${result}
- Failed to write .opencode/openwork.json
- Environment variable store could not be read
- Environment variable store is invalid JSON
AI-assisted analysis of different-ai/openwork@2b7df46e8a (2026-09-01).
Data as JSON: /api/errors/911ffef57509ceca.
Report an issue: GitHub.