{"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":"Error","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/01e15490f04e29cfefe3896951f43db46994d8ee/scripts/lib/github-discussions.js#L13-L49","documentation":"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.","triggerScenarios":"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.","commonSituations":"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.","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."],"exampleFix":"// before\nconst data = runGhJson(['api', 'graphql', '-f', `query=${QUERY}`], {});\n\n// after\ntry {\n  const data = runGhJson(['api', 'graphql', '-f', `query=${QUERY}`], {});\n} catch (err) {\n  if (/authentication required|HTTP 401/i.test(err.message)) {\n    console.error('gh token invalid or expired. Run: gh auth login');\n  }\n  throw err;\n}","handlingStrategy":"try-catch","validationCode":"function ghTokenLooksValid() {\n  const t = process.env.GITHUB_TOKEN || '';\n  return /^gh[pousr]_/.test(t) || t.length >= 20;\n}\nif (!ghTokenLooksValid()) {\n  console.warn('GITHUB_TOKEN missing or malformed; gh may fail with 401');\n}","typeGuard":null,"tryCatchPattern":"try {\n  return runGhJson(args, options);\n} catch (err) {\n  if (/HTTP 401|authentication required/i.test(err.message)) {\n    throw new Error('gh auth failed — run: gh auth login');\n  }\n  if (/rate limit/i.test(err.message)) {\n    // caller may retry after backoff\n    throw err;\n  }\n  throw err;\n}","preventionTips":["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."],"tags":["process","spawn","github","network"],"backgroundTag":null,"analyzedSha":"01e15490f04e29cfefe3896951f43db46994d8ee","analyzedAt":"2026-08-13T00:31:08.655Z","schemaVersion":2},"datasetVersion":"2026-08-13T04:17:16.726Z"}