{"record":{"id":"bda652d92894abd5","repo":"nanocoai/nanoclaw","slug":"stdin-json-input-is-empty-bda652","errorCode":null,"errorMessage":"--stdin-json input is empty","messagePattern":"--stdin-json input is empty","errorType":"validation","errorClass":"StdinJsonInputError","httpStatus":null,"severity":"error","filePath":"src/cli/stdin-json.ts","lineNumber":65,"sourceCode":"  const chunks: Buffer[] = [];\n  let byteLength = 0;\n\n  for await (const chunk of stream) {\n    const buffer = typeof chunk === 'string' ? Buffer.from(chunk, 'utf8') : Buffer.from(chunk);\n    byteLength += buffer.byteLength;\n    if (byteLength > MAX_STDIN_JSON_BYTES) {\n      throw new StdinJsonInputError(`--stdin-json input exceeds ${MAX_STDIN_JSON_BYTES} bytes`);\n    }\n    chunks.push(buffer);\n  }\n\n  return Buffer.concat(chunks, byteLength).toString('utf8');\n}\n\n/** Parse the input, requiring exactly one JSON object — not an array, scalar, or null. */\nfunction parseJsonObject(source: string): Record<string, unknown> {\n  if (source.trim().length === 0) {\n    throw new StdinJsonInputError('--stdin-json input is empty');\n  }\n\n  let parsed: unknown;\n  try {\n    parsed = JSON.parse(source);\n  } catch (err) {\n    throw new StdinJsonInputError('--stdin-json input is not valid JSON', { cause: err });\n  }\n\n  if (parsed === null || typeof parsed !== 'object' || Array.isArray(parsed)) {\n    throw new StdinJsonInputError('--stdin-json input must be one JSON object');\n  }\n\n  return parsed as Record<string, unknown>;\n}\n\n/** Match the key normalization applied by command parsers in crud.ts. */\nfunction canonicalArgKey(key: string): string {","sourceCodeStart":47,"sourceCodeEnd":83,"githubUrl":"https://github.com/nanocoai/nanoclaw/blob/294ef2aee85218b23ad30eda9dfe10e590b54a8c/src/cli/stdin-json.ts#L47-L83","documentation":"parseJsonObject requires the --stdin-json stream to contain exactly one JSON object; empty/whitespace-only input throws before parsing.","triggerScenarios":"Running `ncl ... --stdin-json` with stdin closed, empty, or only whitespace (common in scripts and cron where stdin is /dev/null).","commonSituations":"Interactive prompt eaten by a prior read, CI job with no stdin, or forgetting to pipe the file.","solutions":["Pipe the JSON: `ncl ... --stdin-json < args.json` or `cat args.json | ncl ... --stdin-json`","If no extra args are needed, drop the --stdin-json flag entirely","In scripts, redirect stdin from the intended file, not /dev/null"],"exampleFix":"# before\nncl groups create --name x --stdin-json < /dev/null\n# after\nncl groups create --name x --stdin-json < args.json","handlingStrategy":"validation","validationCode":"const src = fs.readFileSync(path,'utf8');\nif (!src.trim()) throw new Error('empty args file');","typeGuard":"function isNonEmptyJson(s: string): boolean { return s.trim().length > 0; }","tryCatchPattern":null,"preventionTips":["Redirect from a file: `--stdin-json < args.json`","Don't add --stdin-json when there are no extra args"],"tags":["cli","stdin-json","empty-input"],"backgroundTag":"empty-request-body","analyzedSha":"294ef2aee85218b23ad30eda9dfe10e590b54a8c","analyzedAt":"2026-08-28T13:59:10.357Z","schemaVersion":2},"datasetVersion":"2026-08-28T16:17:29.566Z"}