{"record":{"id":"6d18975b20edcfcf","repo":"affaan-m/ECC","slug":"gh-args-join-returned-invalid-json-erro-6d1897","errorCode":null,"errorMessage":"gh ${args.join(' ')} returned invalid JSON: ${error.message}","messagePattern":"gh (.+?) returned invalid JSON: (.+?)","errorType":"exception","errorClass":null,"httpStatus":null,"severity":"error","filePath":"scripts/lib/github-discussions.js","lineNumber":51,"sourceCode":"\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');\n  } catch (error) {\n    throw new Error(`gh ${args.join(' ')} returned invalid JSON: ${error.message}`);\n  }\n}\n\nfunction discussionNeedsMaintainerTouch(discussion) {\n  if (MAINTAINER_ASSOCIATIONS.has(discussion.authorAssociation)) {\n    return false;\n  }\n\n  if (\n    discussion.answer\n    && MAINTAINER_ASSOCIATIONS.has(discussion.answer.authorAssociation)\n  ) {\n    return false;\n  }\n\n  const comments = discussion.comments && Array.isArray(discussion.comments.nodes)\n    ? discussion.comments.nodes\n    : [];","sourceCodeStart":33,"sourceCodeEnd":69,"githubUrl":"https://github.com/affaan-m/ECC/blob/8321021c54d670126ce3b2969d5deb880b4b0c2a/scripts/lib/github-discussions.js#L33-L69","documentation":"runGhJson parses the stdout of a gh command as JSON and throws this when JSON.parse fails, wrapping the underlying parse error message. It indicates gh produced output the module did not expect — non-JSON text such as warnings, human-readable error banners, or HTML from a proxy.","triggerScenarios":"gh emitting non-JSON output for a command whose stdout should be JSON: gh printing a login prompt/banner, proxy/captive-portal HTML pages, gh versions with different output shapes, or stderr warnings interleaved when output is redirected.","commonSituations":"Pinned gh version differs from expected (flag unsupported, output format changed); corporate proxy injecting HTML; gh session expired and gh prompts interactively; calling a gh subcommand that doesn't support --json.","solutions":["Run the exact command printed in the message manually and inspect the raw output.","Upgrade or pin the gh CLI version to one matching the module's expectations.","Remove proxy interference or ensure HTTPS_PROXY points to a trusted proxy returning real responses.","Re-authenticate (`gh auth login` / fresh GH_TOKEN) so gh stops emitting interactive banners."],"exampleFix":"// before\nconst payload = runGhJson(['api', 'repos/o/r']);\n\n// after\ntry {\n  const payload = runGhJson(['api', 'repos/o/r']);\n} catch (e) {\n  if (/invalid JSON/.test(e.message)) {\n    console.error('gh output not JSON — check gh version/auth:', e.message);\n  }\n  throw e;\n}","handlingStrategy":"try-catch","validationCode":"const probe = spawnSync('gh', ['--version'], { encoding: 'utf8' });\nif (probe.status !== 0) throw new Error('gh CLI unavailable or wrong version');","typeGuard":null,"tryCatchPattern":"try {\n  const data = runGhJson(args);\n  return data;\n} catch (e) {\n  if (/returned invalid JSON/.test(e.message)) {\n    console.error('Unexpected gh output — check gh version, proxy, and auth:', e.message);\n  }\n  throw e;\n}","preventionTips":["Pin the gh CLI version in CI to match what the module expects.","Ensure proxies don't inject HTML into HTTPS responses.","Re-authenticate before long-running jobs so gh doesn't emit interactive banners."],"tags":["json","gh","parsing","cli"],"backgroundTag":"json-parse-error","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"}