{"record":{"id":"c35176365f6dc7c4","repo":"headroomlabs-ai/headroom","slug":"command-failed-with-exit-code-result-status","errorCode":null,"errorMessage":"${command} failed with exit code ${result.status ?? \"unknown\"}","messagePattern":"(.+?) failed with exit code (.+?)","errorType":"exception","errorClass":"Error","httpStatus":null,"severity":"error","filePath":"scripts/build_npm_release_assets.mjs","lineNumber":85,"sourceCode":"    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}\n\nfunction readJson(filePath) {\n  return JSON.parse(readFileSync(filePath, \"utf8\"));\n}","sourceCodeStart":67,"sourceCodeEnd":103,"githubUrl":"https://github.com/headroomlabs-ai/headroom/blob/322425c43bffde1ed0b64fecf3cf5951565dd82b/scripts/build_npm_release_assets.mjs#L67-L103","documentation":"The companion failure to the spawn error: the command launched successfully but exited with a non-zero status (or was killed by a signal). Because run() uses stdio: 'inherit', the failing command's own output was already printed to the console above this error — that output, not this message, contains the real cause. This error just halts the multi-step release build at the first failing step.","triggerScenarios":"Any step the script drives (npm pack/build/publish, node tooling) exits non-zero: failed tests or type errors during a prepack, npm publish auth failure, network failure fetching dependencies, a step killed by a signal (status null after termination).","commonSituations":"Running the release script with uncommitted/broken code so npm pack's lifecycle scripts fail; missing or expired npm credentials for the publish step; registry/network hiccups in CI; disk-full conditions making a child process abort.","solutions":["Scroll up in the log and read the output of the exact command named in the message — it identifies the real failure","Reproduce that single command manually in the same directory to iterate on the fix","For npm auth issues, ensure NODE_AUTH_TOKEN / .npmrc is configured in the environment","If status was a signal kill (shown as 'unknown' or null), check CI memory/OOM and disk space"],"exampleFix":"# before\nnode scripts/build_npm_release_assets.mjs\n# ...npm pack output with a failing prepack test above...\n# Error: npm failed with exit code 1\n\n# after: fix the underlying step, then rerun\nnpm test && npm pack  # green before running the release script","handlingStrategy":"try-catch","validationCode":"import { spawnSync } from \"node:child_process\";\n\n// Dry-run the critical steps before the release script\nfunction stepsGreen(cmd: string, args: string[], cwd: string): boolean {\n  return spawnSync(cmd, args, { cwd, stdio: \"inherit\" }).status === 0;\n}\n\nif (!stepsGreen(\"npm\", [\"run\", \"build\"], pkgDir)) {\n  throw new Error(\"Precheck failed: build step is red — fix before running release script\");","typeGuard":"function isStepExitFailure(e: unknown): boolean {\n  // 'failed with exit code N' — the child ran; its own stdout above has the cause\n  return e instanceof Error && / failed with exit code /.test(e.message);\n}","tryCatchPattern":"try {\n  buildAssets();\n} catch (e) {\n  if (e instanceof Error && / failed with exit code /.test(e.message)) {\n    console.error(\"A build step exited non-zero — see its output above this message.\");\n  }\n  throw e;\n}","preventionTips":["Always read the child command's own output above the error — this message only marks which step failed","Keep the repo green (tests, prepack scripts) before invoking the release script","For publish steps, validate npm credentials (NODE_AUTH_TOKEN) as a preflight check"],"tags":["build","ci","nodejs","release"],"backgroundTag":null,"analyzedSha":"322425c43bffde1ed0b64fecf3cf5951565dd82b","analyzedAt":"2026-08-15T01:03:05.481Z","schemaVersion":2},"datasetVersion":"2026-08-15T22:17:37.221Z"}