{"record":{"id":"2345eeca250341b1","repo":"affaan-m/ECC","slug":"command-args-join-failed-result-erro-2345ee","errorCode":null,"errorMessage":"${command} ${args.join(' ')} failed: ${result.error.message}","messagePattern":"(.+?) (.+?) failed: (.+?)","errorType":"exception","errorClass":null,"httpStatus":null,"severity":"error","filePath":"scripts/lib/github-discussions.js","lineNumber":27,"sourceCode":"\nfunction splitRepo(repo) {\n  const [owner, name] = String(repo || '').split('/');\n  if (!owner || !name) {\n    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  }","sourceCodeStart":9,"sourceCodeEnd":45,"githubUrl":"https://github.com/affaan-m/ECC/blob/8321021c54d670126ce3b2969d5deb880b4b0c2a/scripts/lib/github-discussions.js#L9-L45","documentation":"runCommand wraps spawnSync calls (typically to the gh CLI) and throws this when the spawned process itself failed to run — result.error is set. Unlike a non-zero exit status (handled separately), result.error means Node could not spawn or the process was killed (e.g. ENOENT, EACCES, signal termination).","triggerScenarios":"Calling runCommand/runGhJson when the 'gh' binary is not on PATH (ENOENT), the binary lacks execute permission (EACCES), or the child is killed by a signal; spawnSync returns { error } instead of a status.","commonSituations":"GitHub CLI not installed in the container/CI image; PATH stripped in a cron or serverless context; antivirus or permissions blocking execution; ENOMEM from spawning in a constrained environment.","solutions":["Install the GitHub CLI (gh) and confirm `which gh` resolves it on PATH.","Check execute permissions on the binary (chmod +x) if it exists locally.","Run the same command manually to see the underlying spawn error; fix PATH/env passed via options.env.","If ENOMEM/kills occur, reduce concurrency or memory pressure of the parent process."],"exampleFix":"// before\nconst out = runGhJson(['api', 'repos/o/r']);\n\n// after\ntry {\n  const out = runGhJson(['api', 'repos/o/r']);\n} catch (e) {\n  if (!commandExists('gh')) {\n    throw new Error('gh CLI is required: https://cli.github.com');\n  }\n  throw e;\n}","handlingStrategy":"try-catch","validationCode":"const ghOnPath = spawnSync('gh', ['--version']).status === 0;\nif (!ghOnPath) throw new Error('gh CLI not installed or not on PATH');","typeGuard":null,"tryCatchPattern":"try {\n  const out = runCommand('gh', args);\n} catch (e) {\n  if (/failed: .*ENOENT/.test(e.message)) {\n    throw new Error('gh CLI missing — install https://cli.github.com and ensure it is on PATH');\n  }\n  throw e;\n}","preventionTips":["Install gh in every environment (CI image, container, dev machine) the code runs in.","Verify PATH includes gh before spawning in stripped-down contexts (cron, serverless).","Check binary execute permissions after manual installs."],"tags":["cli","spawn","gh","process"],"backgroundTag":"command-not-found","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"}