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 `spawnSync` succeeded in launching the child but it exited with a non-zero status. The message uses the trimmed stderr (falling back to stdout) so the underlying tool's own error text reaches the user. This is the normal failure path for `git`/`gh` returning an error exit code.

Source

Thrown at scripts/platform-audit.js:238

    .replace(/\\/g, '/')
    .replace(/^\.\/+/, '')
    .replace(/\/+$/, '') + (String(value || '').endsWith('/') ? '/' : '');
}

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

  1. Reproduce the failing command manually to read the real stderr, then fix the root cause (auth, scope, network).
  2. For gh auth issues run `gh auth login`; if you rely on GITHUB_TOKEN, pass `--use-env-github-token`.
  3. Point --root at a valid repo worktree if git complained about a missing repository.
  4. Pass `--skip-github` to exclude GitHub-dependent checks when gh is unavailable.

Example fix

# before — GITHUB_TOKEN removed so gh auth fails
node scripts/platform-audit.js
# after — let gh use the env token
node scripts/platform-audit.js --use-env-github-token
Defensive patterns

Strategy: try-catch

Validate before calling

// Pre-flight: can gh authenticate?
function ghReady(useEnvToken) {
  const env = { ...process.env };
  if (!useEnvToken) delete env.GITHUB_TOKEN;
  const r = spawnSync('gh', ['auth','status'], { env, encoding: 'utf8' });
  return r.status === 0;
}

Type guard

function isNonZeroExit(result) {
  return result && result.error === null && typeof result.status === 'number' && result.status !== 0;
}

Try / catch

try {
  runCommand('gh', args, { env });
} catch (err) {
  if (/failed:/.test(err.message) && !/ENOENT/.test(err.message)) {
    console.error(`gh exited non-zero: ${err.message}`);
    if (!options.useEnvGithubToken) console.error('Tip: pass --use-env-github-token if you rely on GITHUB_TOKEN.');
    process.exit(1);
  }
  throw err;
}

Prevention

When it happens

Trigger: `gh` exits non-zero due to auth failure or rate limit; `git status` fails in a non-repo directory; gh query returns an error because the repo is inaccessible; a flag combination the tool rejects.

Common situations: GITHUB_TOKEN expired or lacks scope (note: platform-audit deletes GITHUB_TOKEN unless --use-env-github-token); running outside a git worktree; gh not authed (`gh auth status` failing); network blip causing gh to error.

Related errors


AI-assisted analysis of affaan-m/ECC@01e15490f0 (2026-08-13). Data as JSON: /api/errors/4528586105b26a21. Report an issue: GitHub.