{"record":{"id":"015782b0f6fe90da","repo":"chenglou/pretext","slug":"command-failed-result-exitcode-cmd-join","errorCode":null,"errorMessage":"Command failed (${result.exitCode}): ${cmd.join(' ')}","messagePattern":"Command failed \\((.+?)\\): (.+?)","errorType":"exception","errorClass":"Error","httpStatus":null,"severity":"error","filePath":"scripts/package-smoke-test.ts","lineNumber":186,"sourceCode":"  cmd: string[],\n  options: {\n    cwd: string\n    stdout: 'inherit' | 'pipe'\n    stderr: 'inherit' | 'pipe'\n    allowFailure?: boolean\n  },\n): { exitCode: number, stdout: string, stderr: string } {\n  const result = Bun.spawnSync(cmd, {\n    cwd: options.cwd,\n    stdout: options.stdout,\n    stderr: options.stderr,\n  })\n\n  const stdout = options.stdout === 'pipe' ? new TextDecoder().decode(result.stdout) : ''\n  const stderr = options.stderr === 'pipe' ? new TextDecoder().decode(result.stderr) : ''\n\n  if (!options.allowFailure && result.exitCode !== 0) {\n    throw new Error(`Command failed (${result.exitCode}): ${cmd.join(' ')}`)\n  }\n\n  return {\n    exitCode: result.exitCode,\n    stdout,\n    stderr,\n  }\n}\n","sourceCodeStart":168,"sourceCodeEnd":195,"githubUrl":"https://github.com/chenglou/pretext/blob/ac49b09b7d83ede19581fa94a8b892b07d309baf/scripts/package-smoke-test.ts#L168-L195","documentation":"run() is the shared subprocess wrapper in package-smoke-test.ts. When allowFailure is not set and the spawned command exits non-zero, it throws this generic wrapper with the exit code and the command line. It guards every external process the smoke test shells out to (npm pack, npm install, node, tsc).","triggerScenarios":"`npm pack` fails (missing files/build), `npm install` fails (registry/network, bad tarball), `node index.js` fails (consumer runtime error), or the positive `tsc` compile fails (consumer type error against valid usage).","commonSituations":"Smoke test run on a clean checkout without dist/ built, network/registry problems during install, or a real regression that breaks either the JS ESM consumer or the valid-TS consumer.","solutions":["Identify which command failed from the `cmd.join(' ')` portion of the message.","Reproduce that exact command manually to see its real output (the wrapper inherits stdout/stderr for non-pipe calls, so check the log above the error).","For npm pack: build dist/ first. For npm install: check network/registry. For node/tsc: inspect the consumer error and trace it back to the package export or type surface."],"exampleFix":null,"handlingStrategy":"try-catch","validationCode":null,"typeGuard":null,"tryCatchPattern":"try {\n  run(['npm', 'pack', '--pack-destination', packDir], { cwd: root, stdout: 'inherit', stderr: 'inherit' })\n} catch (e) {\n  const msg = e instanceof Error ? e.message : String(e)\n  if (msg.startsWith('Command failed')) {\n    console.error('Subprocess failed during smoke test. Build dist/ first and check network/registry.')\n    process.exit(1)\n  }\n  throw e\n}","preventionTips":["Build dist/ before running the smoke test so npm pack has files to pack.","Run each external command (npm pack, npm install, node, tsc) manually first when debugging to see real output."],"tags":["subprocess","packaging","smoke-test","npm"],"backgroundTag":null,"analyzedSha":"ac49b09b7d83ede19581fa94a8b892b07d309baf","analyzedAt":"2026-08-12T17:03:16.263Z","schemaVersion":2},"datasetVersion":"2026-08-12T18:17:37.767Z"}