{"record":{"id":"f84d95d55b7666bb","repo":"stablyai/orca","slug":"file-too-large-buffer-bytelength-1024-1024","errorCode":null,"errorMessage":"File too large: ${(buffer.byteLength / 1024 / 1024).toFixed(1)}MB exceeds ${MAX_TEXT_FILE_SIZE / 1024 / 1024}MB limit","messagePattern":"File too large: (.+?)MB exceeds (.+?)MB limit","errorType":"validation","errorClass":"Error","httpStatus":null,"severity":"warning","filePath":"src/main/ipc/filesystem.ts","lineNumber":184,"sourceCode":"  '.ico': 'image/x-icon',\n  '.pdf': 'application/pdf'\n}\nasync function readLocalLogSnapshot(filePath: string): Promise<{\n  content: string\n  isBinary: boolean\n  fileIdentity?: string\n}> {\n  const handle = await open(filePath, 'r')\n  try {\n    const stats = await handle.stat()\n    if (stats.size > MAX_TEXT_FILE_SIZE) {\n      throw new Error(\n        `File too large: ${(stats.size / 1024 / 1024).toFixed(1)}MB exceeds ${MAX_TEXT_FILE_SIZE / 1024 / 1024}MB limit`\n      )\n    }\n    const buffer = await handle.readFile()\n    if (buffer.byteLength > MAX_TEXT_FILE_SIZE) {\n      throw new Error(\n        `File too large: ${(buffer.byteLength / 1024 / 1024).toFixed(1)}MB exceeds ${MAX_TEXT_FILE_SIZE / 1024 / 1024}MB limit`\n      )\n    }\n    if (isBinaryBuffer(buffer)) {\n      return { content: '', isBinary: true }\n    }\n    return {\n      content: buffer.toString('utf8'),\n      isBinary: false,\n      fileIdentity: localLogFileIdentity(stats)\n    }\n  } finally {\n    await handle.close()\n  }\n}\n\ntype DownloadFileResult = { canceled: true } | { canceled: false; destinationPath: string }\n","sourceCodeStart":166,"sourceCodeEnd":202,"githubUrl":"https://github.com/stablyai/orca/blob/1136503c6a231a16dce8f921f6fadb63d181e8db/src/main/ipc/filesystem.ts#L166-L202","documentation":"Thrown by readLocalLogSnapshot as a secondary size check after reading the buffer. Even though the pre-read stat passed, the buffer's actual byteLength is checked again. This catches files that grew between the stat and the readFile call, ensuring the in-memory buffer never exceeds MAX_TEXT_FILE_SIZE (50 MB).","triggerScenarios":"A file whose stat.size was under 50 MB when checked, but grew past 50 MB by the time readFile completed. The buffer.byteLength check catches the post-read size and rejects it.","commonSituations":"Reading an actively growing log file. A process appending to the file between the stat check and the full read. A file being reconstructed or decompressed concurrently during the read.","solutions":["Pause the process writing to the file, then retry.","Copy the file to a stable path and open the copy.","Use a tail-based viewer that reads only the end of the file."],"exampleFix":"// before: read /var/log/app.log while the app is appending\n// after: snapshot the log and read the snapshot\n//   cp /var/log/app.log /tmp/app-snapshot.log\n//   open /tmp/app-snapshot.log with includeLocalLogMetadata","handlingStrategy":"retry","validationCode":null,"typeGuard":null,"tryCatchPattern":"try {\n  const result = await ipcRenderer.invoke('fs:readFile', { filePath, includeLocalLogMetadata: true })\n} catch (error) {\n  if (error instanceof Error && error.message.startsWith('File too large') && error.message.includes('exceeds')) {\n    // file may have grown during read; snapshot and retry\n    showUserWarning('The file grew during read. It will be snapshotted and reopened.')\n    return\n  }\n  throw error\n}","preventionTips":["Pause processes that append to the log file before opening it.","Snapshot the log with `cp` before opening if it is actively growing.","Use log rotation to cap file sizes."],"tags":["size-limit","filesystem","log-snapshot","race-condition","memory","ipc"],"backgroundTag":null,"analyzedSha":"1136503c6a231a16dce8f921f6fadb63d181e8db","analyzedAt":"2026-08-12T23:15:58.167Z","schemaVersion":2},"datasetVersion":"2026-08-12T23:17:12.415Z"}