{"record":{"id":"291f867d5a67ff41","repo":"affaan-m/ECC","slug":"command-args-join-failed-result-std-291f86","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-discussions.js","lineNumber":31,"sourceCode":"    throw new Error(`Invalid repo: ${repo}`);\n  }\n  return { owner, name };\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":13,"sourceCodeEnd":49,"githubUrl":"https://github.com/affaan-m/ECC/blob/8321021c54d670126ce3b2969d5deb880b4b0c2a/scripts/lib/github-discussions.js#L13-L49","documentation":"runCommand throws this when the spawned command completed but exited with a non-zero status. The error message includes the command line plus whatever the child wrote to stderr (falling back to stdout if stderr is empty). This is the normal 'gh CLI rejected the request' path, e.g. auth failures, network errors, or missing repos.","triggerScenarios":"Any runCommand/runGhJson call where gh exits non-zero: unauthenticated gh (no GH_TOKEN and no login), nonexistent repository (404), rate limiting, bad arguments passed in args, or network failures reported by gh on stderr.","commonSituations":"CI job missing a GH_TOKEN/GITHUB_TOKEN; gh never authenticated locally (`gh auth login` not run); typo in repo owner/name; enterprise hosts requiring GH_HOST; expired session.","solutions":["Read the stderr portion of the message for gh's specific complaint and fix accordingly.","Authenticate: run `gh auth login` or set GH_TOKEN/GITHUB_TOKEN in the environment.","Verify the repository string and arguments (owner/name correct, repo exists, you have access).","For rate limits, wait for the reset window or use a token with a higher quota."],"exampleFix":"// before\nconst data = runGhJson(['api', 'repos/o/r']);\n\n// after\ntry {\n  const data = runGhJson(['api', 'repos/o/r']);\n} catch (e) {\n  if (!process.env.GH_TOKEN && !process.env.GITHUB_TOKEN) {\n    throw new Error('Set GH_TOKEN before calling GitHub APIs');\n  }\n  throw e;\n}","handlingStrategy":"retry","validationCode":"const authed = !!(process.env.GH_TOKEN || process.env.GITHUB_TOKEN) || spawnSync('gh', ['auth', 'status']).status === 0;\nif (!authed) throw new Error('gh is not authenticated');","typeGuard":null,"tryCatchPattern":"try {\n  const out = runGhJson(args);\n} catch (e) {\n  if (/rate limit/i.test(e.message)) {\n    await sleep(60_000);\n    return runGhJson(args); // retry once\n  }\n  throw e;\n}","preventionTips":["Set GH_TOKEN/GITHUB_TOKEN in CI and run `gh auth login` locally.","Validate repo/argument values before invoking gh to avoid 404/422 noise.","Retry only transient failures (rate limits, network), never auth or not-found errors."],"tags":["cli","gh","exit-code","process"],"backgroundTag":"http-error-response","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"}