{"record":{"id":"bdb6e70ad9454b15","repo":"affaan-m/ECC","slug":"failed-to-run-gh-result-error-message","errorCode":null,"errorMessage":"Failed to run gh: ${result.error.message}","messagePattern":"Failed to run gh: (.+?)","errorType":"exception","errorClass":"Error","httpStatus":null,"severity":"error","filePath":"scripts/work-items.js","lineNumber":156,"sourceCode":"  const parsed = Number.parseInt(value, 10);\n  if (!Number.isFinite(parsed) || parsed <= 0) {\n    throw new Error(`Invalid limit: ${value}`);\n  }\n  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, '-')","sourceCodeStart":138,"sourceCodeEnd":174,"githubUrl":"https://github.com/affaan-m/ECC/blob/01e15490f04e29cfefe3896951f43db46994d8ee/scripts/work-items.js#L138-L174","documentation":"Thrown by scripts/runGhJson in scripts/work-items.js when Node's spawnSync returns an error object (result.error set) instead of a process result. This happens when the `gh` executable cannot be spawned at all — most commonly because the GitHub CLI is not installed, not on PATH, or (when ECC_GH_SHIM is set) the shim path is invalid. It is an environment-level failure, not a GitHub API failure.","triggerScenarios":"Running `node scripts/work-items.js sync-github --repo owner/repo` on a machine without `gh` installed; CI image that lacks the gh CLI; ECC_GH_SHIM pointing to a nonexistent file; gh present but not executable (permissions).","commonSituations":"Fresh dev machine or minimal Docker image without gh; a CI runner that installs gh conditionally and skipped it; setting ECC_GH_SHIM to a test shim that was since deleted.","solutions":["Install the GitHub CLI (e.g. `brew install gh`, `apt install gh`, or see https://cli.github.com) and confirm `which gh` resolves.","Authenticate with `gh auth login` (a missing auth causes a different error — error 478 — but confirming gh is present is step one).","If using ECC_GH_SHIM, verify the shim file path exists and is executable.","In CI, add an explicit gh installation step and a `gh --version` smoke check before invoking sync-github."],"exampleFix":"// before\nnode scripts/work-items.js sync-github --repo owner/repo\n# Error: Failed to run gh: spawn gh ENOENT\n\n// after\nbrew install gh\ngh auth login\nnode scripts/work-items.js sync-github --repo owner/repo","handlingStrategy":"validation","validationCode":"const { spawnSync } = require('child_process');\nfunction ghAvailable() {\n  const r = spawnSync('gh', ['--version'], { encoding: 'utf8' });\n  return r.status === 0 && /gh version/.test(r.stdout || '');\n}\nif (!ghAvailable()) {\n  throw new Error('GitHub CLI (gh) is required for sync-github. Install from https://cli.github.com');\n}","typeGuard":null,"tryCatchPattern":"// retry once after a short delay if gh spawn fails transiently\nasync function runSyncGithubWithRetry(args, retries = 1) {\n  for (let attempt = 0; attempt <= retries; attempt++) {\n    try {\n      return runWorkItems(args);\n    } catch (e) {\n      if (attempt === retries || !/Failed to run gh/.test(e.message)) throw e;\n      await new Promise(r => setTimeout(r, 2000));\n    }\n  }\n}","preventionTips":["Add a `gh --version` smoke check in CI before any sync-github step.","Install gh in your Docker/CI image explicitly rather than relying on the runner.","If using ECC_GH_SHIM, assert the shim file exists and is executable before invoking."],"tags":["cli","github","spawn","external-dependency","work-items","environment"],"backgroundTag":null,"analyzedSha":"01e15490f04e29cfefe3896951f43db46994d8ee","analyzedAt":"2026-08-13T00:31:08.655Z","schemaVersion":2},"datasetVersion":"2026-08-13T04:17:16.726Z"}