{"record":{"id":"c54aae4c93c65197","repo":"affaan-m/ECC","slug":"command-args-join-failed-result-std","errorCode":null,"errorMessage":"${command} ${args.join(' ')} failed: ${(result.stderr || result.stdout || '').trim()}","messagePattern":"(.+?) (.+?) failed: (.+?)","errorType":"exception","errorClass":null,"httpStatus":null,"severity":"error","filePath":"scripts/lib/github-coordination/gh-api.js","lineNumber":49,"sourceCode":"\nfunction normalizeLabels(labels) {\n  return Array.from(new Set((Array.isArray(labels) ? labels : []).map(normalizeLabelValue).filter(Boolean))).sort();\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\n// ECC_GH_SHIM creates a trust boundary: when set, shimPath replaces the real\n// `gh` binary and command/commandArgs execute an arbitrary script via\n// process.execPath. This variable MUST only be set in trusted, isolated test\n// environments (e.g., a test's own temp directory). Never set ECC_GH_SHIM in\n// production — doing so allows arbitrary script execution under the caller's\n// privileges.\nfunction runGh(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.stripGithubToken) {","sourceCodeStart":31,"sourceCodeEnd":67,"githubUrl":"https://github.com/affaan-m/ECC/blob/8321021c54d670126ce3b2969d5deb880b4b0c2a/scripts/lib/github-coordination/gh-api.js#L31-L67","documentation":"runCommand throws when the spawned command (gh or shim) exits with a non-zero status. The message embeds stderr (or stdout) from the child, forwarding the underlying gh error — e.g. authentication failures, not-found resources, or network errors. It is the pass-through path for any gh CLI failure.","triggerScenarios":"Any runGh call where gh exits non-zero: expired/missing auth (`gh auth` not run), the issue/repo does not exist, no network access, or insufficient permissions on a private repo.","commonSituations":"Running in CI without `gh auth login` / GH_TOKEN set, referencing a repo slug with a typo, hitting rate limits, or a VPN/firewall blocking api.github.com.","solutions":["Read the stderr in the message to identify the underlying gh failure and fix that cause.","Run `gh auth status` and authenticate with `gh auth login` or set GH_TOKEN.","Verify the repo slug (owner/name) and that you have access to it.","Check network connectivity and GitHub API rate-limit status, then retry."],"exampleFix":"// before\nrunGh(['issue', 'view', '123', '-R', 'org/typo-repo']);\n// after\n// verify repo exists first: gh repo view org/correct-repo\nrunGh(['issue', 'view', '123', '-R', 'org/correct-repo']);","handlingStrategy":"try-catch","validationCode":"const auth = require('child_process').spawnSync('gh', ['auth', 'status'], { encoding: 'utf8' });\nif (auth.status !== 0) throw new Error('gh is not authenticated; run `gh auth login` or set GH_TOKEN');","typeGuard":"null","tryCatchPattern":"try {\n  const out = runGh(args);\n} catch (e) {\n  if (/failed: /.test(e.message)) {\n    const stderr = e.message.split('failed: ')[1] || '';\n    if (stderr.includes('auth') || stderr.includes('401')) console.error('Re-authenticate: gh auth login');\n    else if (stderr.includes('404')) console.error('Check repo slug and permissions');\n    else console.error('gh failed:', stderr);\n  } else { throw e; }\n}","preventionTips":["Authenticate in CI with GH_TOKEN secret before running scripts.","Verify repo slugs with `gh repo view <owner>/<name>`.","Log full stderr from the error message to diagnose the root cause.","Retry transient network errors with backoff."],"tags":["gh-cli","exit-code","process"],"backgroundTag":"git-command-failed","analyzedSha":"8321021c54d670126ce3b2969d5deb880b4b0c2a","analyzedAt":"2026-09-16T10:08:13.343Z","contentChangedAt":"2026-09-16T10:08:13.343Z","schemaVersion":2},"datasetVersion":"2026-09-23T08:17:48.524Z"}