{"record":{"id":"66a81cf8f4e4ade3","repo":"affaan-m/ECC","slug":"displaycommand-failed-result-stderr-resu","errorCode":null,"errorMessage":"${displayCommand} failed: ${(result.stderr || result.stdout || '').trim()}","messagePattern":"(.+?) failed: (.+?)","errorType":"exception","errorClass":"Error","httpStatus":null,"severity":"error","filePath":"scripts/work-items.js","lineNumber":160,"sourceCode":"  return parsed;\n}\n\nfunction runGhJson(args) {\n  const shimPath = process.env.ECC_GH_SHIM;\n  const command = shimPath ? process.execPath : 'gh';\n  const commandArgs = shimPath ? [shimPath, ...args] : args;\n  const displayCommand = shimPath ? `node ${shimPath} ${args.join(' ')}` : `gh ${args.join(' ')}`;\n  const result = spawnSync(command, commandArgs, {\n    encoding: 'utf8',\n    maxBuffer: 10 * 1024 * 1024\n  });\n\n  if (result.error) {\n    throw new Error(`Failed to run gh: ${result.error.message}`);\n  }\n\n  if (result.status !== 0) {\n    throw new Error(`${displayCommand} failed: ${(result.stderr || result.stdout || '').trim()}`);\n  }\n\n  try {\n    return JSON.parse(result.stdout || '[]');\n  } catch (error) {\n    throw new Error(`${displayCommand} returned invalid JSON: ${error.message}`);\n  }\n}\n\nfunction slugifyWorkItemSegment(value) {\n  return (\n    String(value || '')\n      .toLowerCase()\n      .replace(/[^a-z0-9]+/g, '-')\n      .replace(/^-+|-+$/g, '') || 'unknown'\n  );\n}\n","sourceCodeStart":142,"sourceCodeEnd":178,"githubUrl":"https://github.com/affaan-m/ECC/blob/01e15490f04e29cfefe3896951f43db46994d8ee/scripts/work-items.js#L142-L178","documentation":"Thrown by scripts/runGhJson in scripts/work-items.js when spawnSync succeeds (gh ran) but exits with a non-zero status. The trimmed stderr (or stdout if no stderr) is appended to the display command so the underlying GitHub CLI failure is visible. Common root causes are authentication failure, a nonexistent or private repo, rate limiting, or a network error reaching GitHub.","triggerScenarios":"`sync-github --repo owner/nonexistent`; gh not authenticated (`gh auth status` shows logged out); GitHub API rate limit exceeded; transient network failure during the `gh pr list` / `gh issue list` calls.","commonSituations":"Running sync-github before `gh auth login`; a repo typed as `repo` instead of `owner/repo`; CI token expired or lacks read scope on the target repo; shared CI runner hitting the unauthenticated rate limit.","solutions":["Run `gh auth status` and, if logged out, `gh auth login` with a token that has repo read scope.","Verify the --repo value is `owner/repo` and that the repo exists and is accessible to the authenticated user.","If rate-limited, wait and retry, or authenticate to raise the limit ceiling.","Read the trimmed stderr in the error message — it carries the exact GitHub CLI reason."],"exampleFix":"// before\nnode scripts/work-items.js sync-github --repo owner/nonexistent\n# Error: gh pr list ... failed: HTTP 404: Not Found\n\n// after\ngh auth login\nnode scripts/work-items.js sync-github --repo owner/existing-repo","handlingStrategy":"retry","validationCode":"const { spawnSync } = require('child_process');\nfunction ghAuthed() {\n  const r = spawnSync('gh', ['auth', 'status'], { encoding: 'utf8' });\n  return r.status === 0;\n}\nfunction ghRepoReadable(repo) {\n  const r = spawnSync('gh', ['repo', 'view', repo], { encoding: 'utf8' });\n  return r.status === 0;\n}\nif (!ghAuthed()) throw new Error('Run `gh auth login` before sync-github');\nif (!ghRepoReadable('owner/repo')) throw new Error('Repo not accessible to current gh auth');","typeGuard":null,"tryCatchPattern":"// Retry transient gh failures (rate limit, network) with backoff\nasync function syncWithRetry(repo, maxRetries = 3) {\n  for (let i = 0; i < maxRetries; i++) {\n    try {\n      return runSync(['sync-github', '--repo', repo]);\n    } catch (e) {\n      const transient = /rate limit|HTTP 5\\d\\d|failed:/i.test(e.message);\n      if (!transient || i === maxRetries - 1) throw e;\n      await new Promise(r => setTimeout(r, 1000 * Math.pow(2, i)));\n    }\n  }\n}","preventionTips":["Run `gh auth status` and ensure a logged-in status before sync-github.","Use a token with `repo` read scope; check the repo slug is owner/repo.","Parse the stderr in the error message — it states the exact GitHub CLI reason.","Add exponential backoff for rate-limit and 5xx responses."],"tags":["cli","github","external-dependency","auth","network","work-items"],"backgroundTag":null,"analyzedSha":"01e15490f04e29cfefe3896951f43db46994d8ee","analyzedAt":"2026-08-13T00:31:08.655Z","schemaVersion":2},"datasetVersion":"2026-08-13T04:17:16.726Z"}