{"record":{"id":"9f203770f764bca1","repo":"affaan-m/ECC","slug":"command-args-join-failed-result-erro","errorCode":null,"errorMessage":"${command} ${args.join(' ')} failed: ${result.error.message}","messagePattern":"(.+?) (.+?) failed: (.+?)","errorType":"exception","errorClass":null,"httpStatus":null,"severity":"error","filePath":"scripts/lib/github-coordination/gh-api.js","lineNumber":45,"sourceCode":"    return String(label.name || label.label || '').trim();\n  }\n  return '';\n}\n\nfunction normalizeLabels(labels) {\n  return Array.from(new Set((Array.isArray(labels) ? labels : []).map(normalizeLabelValue).filter(Boolean))).sort();\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\n// ECC_GH_SHIM creates a trust boundary: when set, shimPath replaces the real\n// `gh` binary and command/commandArgs execute an arbitrary script via\n// process.execPath. This variable MUST only be set in trusted, isolated test\n// environments (e.g., a test's own temp directory). Never set ECC_GH_SHIM in\n// production — doing so allows arbitrary script execution under the caller's\n// privileges.\nfunction runGh(args, options = {}) {\n  const shimPath = process.env.ECC_GH_SHIM;\n  const command = shimPath ? process.execPath : 'gh';","sourceCodeStart":27,"sourceCodeEnd":63,"githubUrl":"https://github.com/affaan-m/ECC/blob/8321021c54d670126ce3b2969d5deb880b4b0c2a/scripts/lib/github-coordination/gh-api.js#L27-L63","documentation":"runCommand spawns a child process (gh or a shim) and throws when the spawn itself errored (result.error is set), meaning the command could not be executed at all — the process never ran to completion. This is distinct from a non-zero exit code (error 212). Typical result.error causes are ENOENT (binary not found), EACCES (not executable), or the process being killed.","triggerScenarios":"Calling runGh (and thus runCommand) when the gh binary is not installed or not on PATH, the ECC_GH_SHIM path points at a missing/non-executable file, or the process is killed by a signal.","commonSituations":"Fresh machines where GitHub CLI was never installed (gh: command not found / ENOENT), a shim path typo in ECC_GH_SHIM, wrong file permissions on a custom shim, or OOM/signals killing the child.","solutions":["Install the GitHub CLI (e.g. brew install gh) and verify with `gh --version`.","Ensure gh is on the PATH of the environment running the script (check options.env / process.env.PATH).","If using ECC_GH_SHIM, verify the shim file exists and is executable (chmod +x).","Re-run the command; transient kills (signals/OOM) may just need a retry."],"exampleFix":"// before\nrunGh(['issue', 'view', '123']) // throws: gh issue view 123 failed: spawn gh ENOENT\n// after\nif (!fs.existsSync(shimPath || 'gh')) throw new Error('gh CLI not found; install GitHub CLI first');\nrunGh(['issue', 'view', '123']);","handlingStrategy":"try-catch","validationCode":"const cmd = process.env.ECC_GH_SHIM || 'gh';\nconst which = require('child_process').spawnSync(cmd, ['--version'], { stdio: 'ignore' });\nif (which.error) throw new Error(`'${cmd}' is not installed/executable; install GitHub CLI`);","typeGuard":"null","tryCatchPattern":"try {\n  const out = runGh(args);\n} catch (e) {\n  if (/failed: spawn .* ENOENT/.test(e.message)) {\n    console.error('gh CLI not found. Install it: https://cli.github.com/');\n  } else {\n    throw e;\n  }\n}","preventionTips":["Install gh and verify with `gh --version` before running scripts.","Keep ECC_GH_SHIM paths absolute and executable (chmod +x).","Do not override options.env in ways that drop PATH.","Monitor for signal/OOM kills when running large batch operations."],"tags":["child-process","spawn","gh-cli"],"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"}