{"record":{"id":"7cc9df31d12512b3","repo":"affaan-m/ECC","slug":"memory-body-is-too-large-maximum-maxbytes-byte","errorCode":null,"errorMessage":"memory body is too large (maximum ${maxBytes} bytes).","messagePattern":"memory body is too large \\(maximum (.+?) bytes\\)\\.","errorType":"validation","errorClass":"Error","httpStatus":null,"severity":"error","filePath":"scripts/memory.js","lineNumber":188,"sourceCode":"      bytesRead = fs.readSync(0, buffer, 0, buffer.length, null);\n    } catch (error) {\n      const retryable = ['EAGAIN', 'EWOULDBLOCK', 'EINTR'].includes(error?.code);\n      if (!retryable) throw error;\n      if (remainingRetryWaitMs < retryDelayMs) {\n        throw new Error(\n          `Standard input remained unavailable after ${maxRetryWaitMs}ms.`\n        );\n      }\n      wait(retryDelayMs);\n      remainingRetryWaitMs -= retryDelayMs;\n      continue;\n    }\n    if (bytesRead === 0) break;\n    chunks.push(buffer.subarray(0, bytesRead));\n    total += bytesRead;\n  }\n  if (total > maxBytes) {\n    throw new Error(`memory body is too large (maximum ${maxBytes} bytes).`);\n  }\n  return decodeUtf8(Buffer.concat(chunks, total), 'memory body from standard input');\n}\n\nfunction readBody(options) {\n  const sources = [Boolean(options.stdin), Boolean(options.bodyFile)]\n    .filter(Boolean).length;\n  if (sources !== 1) {\n    throw new Error('Choose exactly one memory body source: --stdin or --body-file.');\n  }\n  if (options.stdin) {\n    return readBoundedStdin(MAX_BODY_BYTES);\n  }\n\n  const bodyPath = path.resolve(options.bodyFile);\n  return readRegularTextFile(bodyPath, {\n    label: '--body-file',\n    maxBytes: MAX_BODY_BYTES,","sourceCodeStart":170,"sourceCodeEnd":206,"githubUrl":"https://github.com/affaan-m/ECC/blob/8321021c54d670126ce3b2969d5deb880b4b0c2a/scripts/memory.js#L170-L206","documentation":"scripts/memory.js enforces a hard cap on how many bytes it will read from standard input when ingesting a memory body. readBoundedStdin accumulates chunks and throws this error as soon as the cumulative byte total exceeds maxBytes (MAX_BODY_BYTES). It protects the CLI from unbounded stdin (e.g. accidental `cat huge.log | memory save`) before any decode or file write occurs.","triggerScenarios":"Calling `memory save --stdin` (via saveInput -> readBody -> readBoundedStdin) with a stdin payload whose total size exceeds MAX_BODY_BYTES. Any piped or heredoc input larger than the configured maximum triggers the throw after reading completes.","commonSituations":"Piping a large log, JSON dump, or file into the memory CLI; a CI script that redirects an entire artifact to stdin; forgetting to trim/select the relevant snippet before piping; misjudging the cap after a payload grew over time.","solutions":["Shrink the input: pipe only the relevant snippet (head/sed/grep) or split the content into multiple smaller memory saves.","Write the content to a file and use --body-file with a pre-check on file size (stat) if the file path flow allows a larger limit.","Check the configured MAX_BODY_BYTES in scripts/memory.js and raise it deliberately if your workflow legitimately needs larger bodies, then commit that change consciously.","Pre-measure the payload before invoking: `wc -c` on the piped content to confirm it fits the cap."],"exampleFix":"// before\ncat full-incident-log.txt | node scripts/memory.js save --stdin --title \"incident\"\n// after\ngrep -n 'ERROR' full-incident-log.txt | head -200 | node scripts/memory.js save --stdin --title \"incident errors\"","handlingStrategy":"validation","validationCode":"const size = Number(process.env.CLI_STDIN_BYTES ?? 0);\nif (payload.length > MAX_BODY_BYTES) {\n  throw new Error(`Input is ${payload.length} bytes; memory accepts at most ${MAX_BODY_BYTES}.`);\n}","typeGuard":null,"tryCatchPattern":"try {\n  runMemorySave(body);\n} catch (err) {\n  if (String(err.message).includes('memory body is too large')) {\n    console.error('Input exceeds the memory body limit; trim or split the content.');\n    process.exitCode = 2;\n  } else throw err;\n}","preventionTips":["Run `wc -c` on piped content before invoking memory save.","Extract only the relevant excerpt (grep/head) instead of piping whole files.","Keep MAX_BODY_BYTES in mind when designing CI jobs that stream artifacts to the CLI.","Prefer --body-file with a size pre-check for large but bounded content."],"tags":["cli","input-validation","stdin","payload-too-large"],"backgroundTag":"payload-too-large","analyzedSha":"8321021c54d670126ce3b2969d5deb880b4b0c2a","analyzedAt":"2026-09-16T10:08:13.343Z","contentChangedAt":"2026-09-16T10:08:13.343Z","schemaVersion":2},"datasetVersion":"2026-09-23T08:17:48.524Z"}