{"record":{"id":"959b35729f465222","repo":"affaan-m/ECC","slug":"command-args-join-failed-result-erro-959b35","errorCode":null,"errorMessage":"${command} ${args.join(' ')} failed: ${result.error.message}","messagePattern":"(.+?) (.+?) failed: (.+?)","errorType":"exception","errorClass":null,"httpStatus":null,"severity":"error","filePath":"scripts/platform-audit.js","lineNumber":234,"sourceCode":"}\n\nfunction normalizeRelativePrefix(value) {\n  return String(value || '')\n    .replace(/\\\\/g, '/')\n    .replace(/^\\.\\/+/, '')\n    .replace(/\\/+$/, '') + (String(value || '').endsWith('/') ? '/' : '');\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":216,"sourceCodeEnd":252,"githubUrl":"https://github.com/affaan-m/ECC/blob/8321021c54d670126ce3b2969d5deb880b4b0c2a/scripts/platform-audit.js#L216-L252","documentation":"runCommand in scripts/platform-audit.js spawns a child process with spawnSync and throws this error when spawn itself reports result.error — i.e. the process could not be spawned, was killed, or failed before producing a status code. The message embeds the failing command line and Node's underlying error message (e.g. ENOENT). It is distinct from a non-zero exit, which produces the sibling error at line 238.","triggerScenarios":"Calling runCommand with a command binary that does not exist on PATH (ENOENT), lacks execute permission (EACCES), or is killed by a signal; any caller such as runGhJson invoking a missing `gh` binary.","commonSituations":"`gh` CLI not installed in the environment running the audit; CI containers missing the tool; PATH differences between local shells and spawned environments; Windows without a shell wrapper.","solutions":["Install the missing binary (e.g. `gh`) or fix its PATH so it resolves","Verify the command is executable (chmod +x, correct absolute path)","Add a preflight check like `command -v gh` before running the audit","Read the embedded result.error.message (ENOENT/EACCES/ETIMEDOUT) to identify the spawn cause"],"exampleFix":"// before\nconst stdout = runCommand('gh', ['pr', 'list']);\n// after\nif (!commandExists('gh')) {\n  throw new Error('gh CLI not found; install it or extend PATH');\n}\nconst stdout = runCommand('gh', ['pr', 'list']);","handlingStrategy":"try-catch","validationCode":"const { execFileSync } = require('child_process');\nfunction commandExists(cmd) {\n  try { execFileSync(cmd, ['--version'], { stdio: 'ignore' }); return true; }\n  catch (e) { return e.code !== 'ENOENT'; }\n}","typeGuard":"function isSpawnError(result) {\n  return result != null && typeof result === 'object' && 'error' in result && result.error instanceof Error;\n}","tryCatchPattern":"try {\n  const out = runCommand('gh', ['pr', 'list']);\n} catch (e) {\n  if (e.message.includes('failed:') && /ENOENT|EACCES/.test(e.message)) {\n    console.error('Required CLI not installed or not executable:', e.message);\n    process.exitCode = 127;\n  } else throw e;\n}","preventionTips":["Verify required binaries (gh, git) exist in the runtime environment","Pin tool installation in CI images before running audits","Check PATH inside spawned contexts matches your shell's PATH","Handle ENOENT vs EACCES differently — install vs chmod"],"tags":["cli","subprocess","spawn"],"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"}