headroomlabs-ai/headroom · error · Error

${command} failed with exit code ${result.status ?? "unknown

Error message

${command} failed with exit code ${result.status ?? "unknown"}

What it means

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.

Source

Thrown at scripts/build_npm_release_assets.mjs:85

    return arg;
  }
  return `"${arg.replace(/"/g, '""')}"`;
}

function run(command, args, cwd) {
  console.log(`\n> ${command} ${args.map(quoteCmdArg).join(" ")}`);
  const result = spawnSync(command, args, {
    cwd,
    encoding: "utf8",
    stdio: "inherit",
  });

  if (result.error) {
    throw new Error(`${command} failed: ${result.error.message}`);
  }

  if (result.status !== 0) {
    throw new Error(`${command} failed with exit code ${result.status ?? "unknown"}`);
  }
}

function runNpm(args, cwd) {
  if (process.platform === "win32") {
    run("cmd.exe", ["/d", "/s", "/c", "npm.cmd", ...args], cwd);
    return;
  }
  run("npm", args, cwd);
}

function runNode(args, cwd) {
  run(process.execPath, args, cwd);
}

function readJson(filePath) {
  return JSON.parse(readFileSync(filePath, "utf8"));
}

View on GitHub (pinned to 322425c43b)

Solutions

  1. Scroll up in the log and read the output of the exact command named in the message — it identifies the real failure
  2. Reproduce that single command manually in the same directory to iterate on the fix
  3. For npm auth issues, ensure NODE_AUTH_TOKEN / .npmrc is configured in the environment
  4. If status was a signal kill (shown as 'unknown' or null), check CI memory/OOM and disk space

Example fix

# before
node scripts/build_npm_release_assets.mjs
# ...npm pack output with a failing prepack test above...
# Error: npm failed with exit code 1

# after: fix the underlying step, then rerun
npm test && npm pack  # green before running the release script
Defensive patterns

Strategy: try-catch

Validate before calling

import { spawnSync } from "node:child_process";

// Dry-run the critical steps before the release script
function stepsGreen(cmd: string, args: string[], cwd: string): boolean {
  return spawnSync(cmd, args, { cwd, stdio: "inherit" }).status === 0;
}

if (!stepsGreen("npm", ["run", "build"], pkgDir)) {
  throw new Error("Precheck failed: build step is red — fix before running release script");

Type guard

function isStepExitFailure(e: unknown): boolean {
  // 'failed with exit code N' — the child ran; its own stdout above has the cause
  return e instanceof Error && / failed with exit code /.test(e.message);
}

Try / catch

try {
  buildAssets();
} catch (e) {
  if (e instanceof Error && / failed with exit code /.test(e.message)) {
    console.error("A build step exited non-zero — see its output above this message.");
  }
  throw e;
}

Prevention

When it happens

Trigger: 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).

Common situations: 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.

Related errors


AI-assisted analysis of headroomlabs-ai/headroom@322425c43b (2026-08-15). Data as JSON: /api/errors/c35176365f6dc7c4. Report an issue: GitHub.