{"record":{"id":"6abbd99f060f038b","repo":"headroomlabs-ai/headroom","slug":"command-failed-result-error-message","errorCode":null,"errorMessage":"${command} failed: ${result.error.message}","messagePattern":"(.+?) failed: (.+?)","errorType":"exception","errorClass":"Error","httpStatus":null,"severity":"error","filePath":"scripts/build_npm_release_assets.mjs","lineNumber":81,"sourceCode":"\nfunction quoteCmdArg(value) {\n  const arg = String(value);\n  if (/^[A-Za-z0-9_./:=\\\\-]+$/.test(arg)) {\n    return arg;\n  }\n  return `\"${arg.replace(/\"/g, '\"\"')}\"`;\n}\n\nfunction run(command, args, cwd) {\n  console.log(`\\n> ${command} ${args.map(quoteCmdArg).join(\" \")}`);\n  const result = spawnSync(command, args, {\n    cwd,\n    encoding: \"utf8\",\n    stdio: \"inherit\",\n  });\n\n  if (result.error) {\n    throw new Error(`${command} failed: ${result.error.message}`);\n  }\n\n  if (result.status !== 0) {\n    throw new Error(`${command} failed with exit code ${result.status ?? \"unknown\"}`);\n  }\n}\n\nfunction runNpm(args, cwd) {\n  if (process.platform === \"win32\") {\n    run(\"cmd.exe\", [\"/d\", \"/s\", \"/c\", \"npm.cmd\", ...args], cwd);\n    return;\n  }\n  run(\"npm\", args, cwd);\n}\n\nfunction runNode(args, cwd) {\n  run(process.execPath, args, cwd);\n}","sourceCodeStart":63,"sourceCodeEnd":99,"githubUrl":"https://github.com/headroomlabs-ai/headroom/blob/322425c43bffde1ed0b64fecf3cf5951565dd82b/scripts/build_npm_release_assets.mjs#L63-L99","documentation":"In build_npm_release_assets.mjs, run() wraps spawnSync; result.error is set when the command could not be launched at all (ENOENT, EACCES, EMFILE…) — not when it runs and exits non-zero. The message embeds the underlying spawn error, e.g. 'spawn npm ENOENT'. This is a build-script precondition failure: the required tool is missing or not executable in the build environment.","triggerScenarios":"The release asset script invokes npm/node/other commands that do not exist on PATH in the build container or shell; a Windows run hitting a non-.cmd binary; execute permission missing on a helper script.","commonSituations":"CI image built without Node/npm or with them installed outside PATH; running the script via a different user than the one that installed the toolchain; nvm/fnm environment not loaded in the CI step; local run after switching package managers.","solutions":["Check the error string — ENOENT means the binary was not found: install it or fix PATH (e.g. source nvm, add npm's global bin dir)","Verify with 'which <command>' in the exact environment the script runs in (same user, same container)","On CI, run a setup step (actions/setup-node or apt-get install nodejs npm) before the script","If it is EACCES/permission-related, fix the binary's execute bits or run with appropriate permissions"],"exampleFix":"# before: CI step runs script without node on PATH\nnode scripts/build_npm_release_assets.mjs  # 'node failed: spawn npm ENOENT'\n\n# after: ensure toolchain present first\n- uses: actions/setup-node@v4\n  with: { node-version: 20 }\n- run: node scripts/build_npm_release_assets.mjs","handlingStrategy":"try-catch","validationCode":"import { spawnSync } from \"node:child_process\";\n\nfunction commandLaunchable(cmd: string): boolean {\n  const r = spawnSync(cmd, [\"--version\"], { stdio: \"ignore\" });\n  return r.error === undefined;\n}\n\nfor (const cmd of [\"npm\", \"node\"]) {\n  if (!commandLaunchable(cmd)) {\n    throw new Error(`${cmd} not launchable — fix PATH before running the release build`);\n  }\n}","typeGuard":"function isSpawnLaunchError(e: unknown): e is Error {\n  // Distinguish 'could not launch' (ENOENT/EACCES) from 'ran and failed'\n  return e instanceof Error && / failed: (spawn|ENOENT|EACCES)/.test(e.message);\n}","tryCatchPattern":"try {\n  buildAssets();\n} catch (e) {\n  if (e instanceof Error && e.message.includes(\"failed: spawn\")) {\n    console.error(\"Build tool missing from PATH — install it or fix PATH and rerun.\");\n    process.exitCode = 1;\n  } else {\n    throw e;\n  }\n}","preventionTips":["Run release builds in a container/CI image with the full Node toolchain preinstalled","Assert 'npm --version' and 'node --version' at job start so PATH problems surface immediately","Load nvm/fnm environment in the same shell that invokes the script"],"tags":["build","ci","nodejs","environment"],"backgroundTag":null,"analyzedSha":"322425c43bffde1ed0b64fecf3cf5951565dd82b","analyzedAt":"2026-08-15T01:03:05.481Z","schemaVersion":2},"datasetVersion":"2026-08-15T22:17:37.221Z"}