{"record":{"id":"911ffef57509ceca","repo":"different-ai/openwork","slug":"file-too-large-911ffe","errorCode":"FILE_TOO_LARGE","errorMessage":"File exceeds the configured read limit","messagePattern":"File exceeds the configured read limit","errorType":"error_code","errorClass":"Error","httpStatus":null,"severity":"error","filePath":"apps/server/src/jsonc.ts","lineNumber":63,"sourceCode":" * Read a small diagnostics input without following symlinks or opening a FIFO\n * in blocking mode. The size is checked both before and while reading so a\n * file that grows after inspection cannot exceed the caller's memory budget.\n */\nexport async function readBoundedRegularTextFile(\n  path: string,\n  options: { maxBytes: number; signal?: AbortSignal },\n): Promise<string> {\n  if (!Number.isSafeInteger(options.maxBytes) || options.maxBytes < 0) {\n    throw new RangeError(\"maxBytes must be a non-negative safe integer\");\n  }\n  throwIfAborted(options.signal);\n  const pathMetadata = await lstat(path);\n  throwIfAborted(options.signal);\n  if (!pathMetadata.isFile()) {\n    throw fileReadError(\"NOT_REGULAR_FILE\", \"Expected a regular file\");\n  }\n  if (pathMetadata.size > options.maxBytes) {\n    throw fileReadError(\"FILE_TOO_LARGE\", \"File exceeds the configured read limit\");\n  }\n\n  const nonBlockingFlags = process.platform === \"win32\"\n    ? 0\n    : constants.O_NONBLOCK | constants.O_NOFOLLOW;\n  const handle = await open(path, constants.O_RDONLY | nonBlockingFlags);\n  try {\n    const openedMetadata = await handle.stat();\n    throwIfAborted(options.signal);\n    if (!openedMetadata.isFile()) {\n      throw fileReadError(\"NOT_REGULAR_FILE\", \"Expected a regular file\");\n    }\n    if (openedMetadata.size > options.maxBytes) {\n      throw fileReadError(\"FILE_TOO_LARGE\", \"File exceeds the configured read limit\");\n    }\n\n    const chunks: Buffer[] = [];\n    let totalBytes = 0;","sourceCodeStart":45,"sourceCodeEnd":81,"githubUrl":"https://github.com/different-ai/openwork/blob/2b7df46e8ae1517d64c896c7793d2d52ec845669/apps/server/src/jsonc.ts#L45-L81","documentation":"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.","triggerScenarios":"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).","commonSituations":"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.","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."],"exampleFix":"// before\nconst raw = await readJsoncFile(bigPath, { maxBytes: 64 * 1024 }); // 2MB file -> FILE_TOO_LARGE\n// after\nconst st = await fs.stat(bigPath);\nconst raw = await readJsoncFile(bigPath, { maxBytes: Math.max(64 * 1024, st.size + 1024) });","handlingStrategy":"validation","validationCode":"const st = await fs.stat(path);\nconst MAX = 64 * 1024;\nif (st.size > MAX) throw new Error(`${path} is ${st.size} bytes, limit ${MAX}`);","typeGuard":"null","tryCatchPattern":"try {\n  return await readJsoncFile(path, { maxBytes: MAX });\n} catch (e) {\n  if ((e as NodeJS.ErrnoException).code === \"FILE_TOO_LARGE\") return readBoundedTail(path, MAX);\n  throw e;\n}","preventionTips":["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."],"tags":["filesystem","size-limit","jsonc","bounded-read"],"backgroundTag":"file-exceeds-size-limit","analyzedSha":"2b7df46e8ae1517d64c896c7793d2d52ec845669","analyzedAt":"2026-09-01T07:59:23.713Z","contentChangedAt":null,"schemaVersion":2},"datasetVersion":"2026-09-08T10:18:20.063Z"}