nanocoai/nanoclaw · error · StdinJsonInputError
--stdin-json input is empty
Error message
--stdin-json input is empty
What it means
parseJsonObject requires the --stdin-json stream to contain exactly one JSON object; empty/whitespace-only input throws before parsing.
Source
Thrown at src/cli/stdin-json.ts:65
const chunks: Buffer[] = [];
let byteLength = 0;
for await (const chunk of stream) {
const buffer = typeof chunk === 'string' ? Buffer.from(chunk, 'utf8') : Buffer.from(chunk);
byteLength += buffer.byteLength;
if (byteLength > MAX_STDIN_JSON_BYTES) {
throw new StdinJsonInputError(`--stdin-json input exceeds ${MAX_STDIN_JSON_BYTES} bytes`);
}
chunks.push(buffer);
}
return Buffer.concat(chunks, byteLength).toString('utf8');
}
/** Parse the input, requiring exactly one JSON object — not an array, scalar, or null. */
function parseJsonObject(source: string): Record<string, unknown> {
if (source.trim().length === 0) {
throw new StdinJsonInputError('--stdin-json input is empty');
}
let parsed: unknown;
try {
parsed = JSON.parse(source);
} catch (err) {
throw new StdinJsonInputError('--stdin-json input is not valid JSON', { cause: err });
}
if (parsed === null || typeof parsed !== 'object' || Array.isArray(parsed)) {
throw new StdinJsonInputError('--stdin-json input must be one JSON object');
}
return parsed as Record<string, unknown>;
}
/** Match the key normalization applied by command parsers in crud.ts. */
function canonicalArgKey(key: string): string {View on GitHub (pinned to 294ef2aee8)
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
Example fix
# before ncl groups create --name x --stdin-json < /dev/null # after ncl groups create --name x --stdin-json < args.json
Defensive patterns
Strategy: validation
Validate before calling
const src = fs.readFileSync(path,'utf8');
if (!src.trim()) throw new Error('empty args file'); Type guard
function isNonEmptyJson(s: string): boolean { return s.trim().length > 0; } Prevention
- Redirect from a file: `--stdin-json < args.json`
- Don't add --stdin-json when there are no extra args
When it happens
Trigger: Running `ncl ... --stdin-json` with stdin closed, empty, or only whitespace (common in scripts and cron where stdin is /dev/null).
Common situations: Interactive prompt eaten by a prior read, CI job with no stdin, or forgetting to pipe the file.
Related errors
- --stdin-json input exceeds ${MAX_STDIN_JSON_BYTES} bytes
- --stdin-json input is not valid JSON
- --stdin-json input must be one JSON object
- --stdin-json key "__proto__" is not allowed
- --stdin-json key "${key}" is also supplied on argv
AI-assisted analysis of nanocoai/nanoclaw@294ef2aee8 (2026-08-28).
Data as JSON: /api/errors/bda652d92894abd5.
Report an issue: GitHub.