affaan-m/ECC · error · Error
${command} ${args.join(' ')} failed: ${(result.stderr || res
Error message
${command} ${args.join(' ')} failed: ${(result.stderr || result.stdout || '').trim()} What it means
Thrown by runCommand() when the child process spawned successfully but exited with a non-zero status. The message embeds the trimmed stderr (falling back to stdout) so the underlying gh CLI error surfaces verbatim.
Source
Thrown at scripts/lib/github-discussions.js:31
throw new Error(`Invalid repo: ${repo}`);
}
return { owner, name };
}
function runCommand(command, args, options = {}) {
const result = spawnSync(command, args, {
cwd: options.cwd,
env: options.env || process.env,
encoding: 'utf8',
maxBuffer: 10 * 1024 * 1024,
});
if (result.error) {
throw new Error(`${command} ${args.join(' ')} failed: ${result.error.message}`);
}
if (result.status !== 0) {
throw new Error(`${command} ${args.join(' ')} failed: ${(result.stderr || result.stdout || '').trim()}`);
}
return result.stdout || '';
}
function runGhJson(args, options = {}) {
const shimPath = process.env.ECC_GH_SHIM;
const command = shimPath ? process.execPath : 'gh';
const commandArgs = shimPath ? [shimPath, ...args] : args;
const env = { ...process.env };
if (!options.useEnvGithubToken) {
delete env.GITHUB_TOKEN;
}
const stdout = runCommand(command, commandArgs, { env });
try {
return JSON.parse(stdout || 'null');View on GitHub (pinned to 01e15490f0)
Solutions
- Read the embedded stderr in the error message; it usually states the exact gh failure.
- Re-authenticate: gh auth login --scopes repo, then verify: gh auth status.
- If rate limited, wait and retry; consider caching the response.
- Confirm the repo exists and the token has access: gh repo view <owner>/<name>.
- Check connectivity: gh api user >/dev/null.
Example fix
// before
const data = runGhJson(['api', 'graphql', '-f', `query=${QUERY}`], {});
// after
try {
const data = runGhJson(['api', 'graphql', '-f', `query=${QUERY}`], {});
} catch (err) {
if (/authentication required|HTTP 401/i.test(err.message)) {
console.error('gh token invalid or expired. Run: gh auth login');
}
throw err;
} Defensive patterns
Strategy: try-catch
Validate before calling
function ghTokenLooksValid() {
const t = process.env.GITHUB_TOKEN || '';
return /^gh[pousr]_/.test(t) || t.length >= 20;
}
if (!ghTokenLooksValid()) {
console.warn('GITHUB_TOKEN missing or malformed; gh may fail with 401');
} Try / catch
try {
return runGhJson(args, options);
} catch (err) {
if (/HTTP 401|authentication required/i.test(err.message)) {
throw new Error('gh auth failed — run: gh auth login');
}
if (/rate limit/i.test(err.message)) {
// caller may retry after backoff
throw err;
}
throw err;
} Prevention
- Run gh auth status in CI before invoking scripts that call gh.
- Confirm token scopes include repo and read:org as needed.
- Surface stderr verbatim to the operator so they can act on the real gh message.
When it happens
Trigger: runCommand returns result.status !== 0. For gh this usually means authentication failure, rate limit, network/GraphQL error, unknown repo, missing scope, or invalid GraphQL query.
Common situations: gh auth token expired or lacks repo/read:org scope; rate limit hit; network proxy blocking api.github.com; repo is private and token lacks access; GraphQL query references a field removed in a GitHub schema update; ECC_GH_SHIM wrote an error to stderr.
Related errors
- ${command} ${args.join(' ')} failed: ${result.error.message}
- Command "${commandName}" terminated by signal ${result.signa
- ${command} ${args.join(' ')} failed: ${(result.stderr || res
- gh ${args.join(' ')} returned invalid JSON: ${error.message}
- Failed to run gh: ${result.error.message}
AI-assisted analysis of affaan-m/ECC@01e15490f0 (2026-08-13).
Data as JSON: /api/errors/291f867d5a67ff41.
Report an issue: GitHub.