affaan-m/ECC · error · Error
returned invalid JSON
Error message
${displayCommand} returned invalid JSON: ${error.message} What it means
runGhJson throws when the gh command succeeded but its stdout is not valid JSON (empty output, human-readable error text, or truncated output). The faulting input is the gh stdout stream; JSON.parse's message is embedded.
Solutions
- Re-run the gh command manually with the same args to inspect its raw output.
- Ensure the gh version supports the JSON fields requested (--json with valid field names).
- Check ECC_GH_SHIM: a shim returning non-JSON output will trigger this.
Defensive patterns
Strategy: try-catch
When it happens
Trigger: Thrown at scripts/work-items.js:166 when the library encounters an invalid state.
Common situations: See trigger scenarios.
Understand the failure class
- Parsing and encoding errors: unexpected token, malformed input — why parsers reject input and how to find the real culprit.
AI-assisted analysis of affaan-m/ECC@8321021c54 (2026-09-16).
Data as JSON: /api/errors/27c7efc9fbe36990.
Report an issue: GitHub.
Appendix: source
Thrown at scripts/work-items.js:166
const commandArgs = shimPath ? [shimPath, ...args] : args;
const displayCommand = shimPath ? `node ${shimPath} ${args.join(' ')}` : `gh ${args.join(' ')}`;
const result = spawnSync(command, commandArgs, {
encoding: 'utf8',
maxBuffer: 10 * 1024 * 1024
});
if (result.error) {
throw new Error(`Failed to run gh: ${result.error.message}`);
}
if (result.status !== 0) {
throw new Error(`${displayCommand} failed: ${(result.stderr || result.stdout || '').trim()}`);
}
try {
return JSON.parse(result.stdout || '[]');
} catch (error) {
throw new Error(`${displayCommand} returned invalid JSON: ${error.message}`);
}
}
function slugifyWorkItemSegment(value) {
return (
String(value || '')
.toLowerCase()
.replace(/[^a-z0-9]+/g, '-')
.replace(/^-+|-+$/g, '') || 'unknown'
);
}
function githubWorkItemId(repo, type, number) {
return `github-${slugifyWorkItemSegment(repo)}-${type}-${number}`;
}
function githubPrStatus(pr) {
if (pr.isDraft || pr.mergeStateStatus === 'DIRTY') {View on GitHub (pinned to 8321021c54)