{"record":{"id":"4528586105b26a21","repo":"affaan-m/ECC","slug":"command-args-join-failed-result-std-452858","errorCode":null,"errorMessage":"${command} ${args.join(' ')} failed: ${(result.stderr || result.stdout || '').trim()}","messagePattern":"(.+?) (.+?) failed: (.+?)","errorType":"exception","errorClass":"Error","httpStatus":null,"severity":"error","filePath":"scripts/platform-audit.js","lineNumber":238,"sourceCode":"    .replace(/\\\\/g, '/')\n    .replace(/^\\.\\/+/, '')\n    .replace(/\\/+$/, '') + (String(value || '').endsWith('/') ? '/' : '');\n}\n\nfunction runCommand(command, args, options = {}) {\n  const result = spawnSync(command, args, {\n    cwd: options.cwd,\n    env: options.env || process.env,\n    encoding: 'utf8',\n    maxBuffer: 10 * 1024 * 1024,\n  });\n\n  if (result.error) {\n    throw new Error(`${command} ${args.join(' ')} failed: ${result.error.message}`);\n  }\n\n  if (result.status !== 0) {\n    throw new Error(`${command} ${args.join(' ')} failed: ${(result.stderr || result.stdout || '').trim()}`);\n  }\n\n  return result.stdout || '';\n}\n\nfunction runGhJson(args, options = {}) {\n  const shimPath = process.env.ECC_GH_SHIM;\n  const command = shimPath ? process.execPath : 'gh';\n  const commandArgs = shimPath ? [shimPath, ...args] : args;\n  const env = { ...process.env };\n\n  if (!options.useEnvGithubToken) {\n    delete env.GITHUB_TOKEN;\n  }\n\n  const stdout = runCommand(command, commandArgs, { env });\n  try {\n    return JSON.parse(stdout || 'null');","sourceCodeStart":220,"sourceCodeEnd":256,"githubUrl":"https://github.com/affaan-m/ECC/blob/01e15490f04e29cfefe3896951f43db46994d8ee/scripts/platform-audit.js#L220-L256","documentation":"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.","triggerScenarios":"`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.","commonSituations":"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.","solutions":["Reproduce the failing command manually to read the real stderr, then fix the root cause (auth, scope, network).","For gh auth issues run `gh auth login`; if you rely on GITHUB_TOKEN, pass `--use-env-github-token`.","Point --root at a valid repo worktree if git complained about a missing repository.","Pass `--skip-github` to exclude GitHub-dependent checks when gh is unavailable."],"exampleFix":"# before — GITHUB_TOKEN removed so gh auth fails\nnode scripts/platform-audit.js\n# after — let gh use the env token\nnode scripts/platform-audit.js --use-env-github-token","handlingStrategy":"try-catch","validationCode":"// Pre-flight: can gh authenticate?\nfunction ghReady(useEnvToken) {\n  const env = { ...process.env };\n  if (!useEnvToken) delete env.GITHUB_TOKEN;\n  const r = spawnSync('gh', ['auth','status'], { env, encoding: 'utf8' });\n  return r.status === 0;\n}","typeGuard":"function isNonZeroExit(result) {\n  return result && result.error === null && typeof result.status === 'number' && result.status !== 0;\n}","tryCatchPattern":"try {\n  runCommand('gh', args, { env });\n} catch (err) {\n  if (/failed:/.test(err.message) && !/ENOENT/.test(err.message)) {\n    console.error(`gh exited non-zero: ${err.message}`);\n    if (!options.useEnvGithubToken) console.error('Tip: pass --use-env-github-token if you rely on GITHUB_TOKEN.');\n    process.exit(1);\n  }\n  throw err;\n}","preventionTips":["Run `gh auth login` and verify `gh auth status` before auditing.","Pass --use-env-github-token if your CI injects GITHUB_TOKEN.","Point --root at a valid git worktree to avoid git failures."],"tags":["spawn","platform-audit","gh","exit-status"],"backgroundTag":null,"analyzedSha":"01e15490f04e29cfefe3896951f43db46994d8ee","analyzedAt":"2026-08-13T00:31:08.655Z","schemaVersion":2},"datasetVersion":"2026-08-13T04:17:16.726Z"}