{"record":{"id":"8d3bc889fa2ef303","repo":"oven-sh/bun","slug":"options-label-cmd-0-r-error-message","errorCode":null,"errorMessage":"${options.label ?? cmd[0]}: ${r.error.message}","messagePattern":"\\$\\{options\\.label \\?\\? cmd\\[0\\]\\}: \\$\\{r\\.error\\.message\\}","errorType":"exception","errorClass":"Error","httpStatus":null,"severity":"error","filePath":"scripts/orderfile/generate.ts","lineNumber":112,"sourceCode":"\n/**\n * Runs a command to completion, throwing if it could not be spawned. Exported so\n * a test can drive it under node: bun's spawnSync delivers `input` whatever stdin\n * is, so the wiring below only ever breaks on CI, which builds under node.\n */\nexport function runCommand(cmd: string[], options: RunOptions = {}) {\n  const r = spawnSync(cmd[0]!, cmd.slice(1), {\n    env: { ...process.env, ...options.env },\n    cwd: options.cwd,\n    input: options.input,\n    timeout: options.timeout,\n    // Only a pipe carries `input`: node drops it when stdin is \"ignore\", and\n    // then an interactive workload reads nothing and waits forever for a line.\n    stdio: [options.input === undefined ? \"ignore\" : \"pipe\", \"pipe\", \"pipe\"],\n    maxBuffer: 1 << 29, // nm prints ~10 MB of symbols\n  });\n  // A timeout arrives here too: spawnSync reports it as an ETIMEDOUT error.\n  if (r.error) throw new Error(`${options.label ?? cmd[0]}: ${r.error.message}`);\n  return r;\n}\n\nexport interface GenerateOptions {\n  /** Build directory holding the unstripped binary. */\n  buildDir: string;\n  /** Unstripped binary to trace. Defaults to `bun-profile`; an assertions build names it differently. */\n  exeName?: string;\n  /** Where to write the order file. Defaults to `<buildDir>/linker.order`. */\n  outPath?: string;\n  /** Fail if fewer than this many functions were traced. */\n  minFunctions?: number;\n  /** Print per-workload progress. */\n  verbose?: boolean;\n}\n\n/**\n * Linker-visible function names, by address. Multiple names can share one","sourceCodeStart":94,"sourceCodeEnd":130,"githubUrl":"https://github.com/oven-sh/bun/blob/8c5296ac459e8252d3cd702f3fbcbb0c249d95d5/scripts/orderfile/generate.ts#L94-L130","documentation":"The runCommand helper in scripts/orderfile/generate.ts wraps spawnSync and throws when r.error is set — meaning the command never ran successfully as a process: cmd[0] was not found (ENOENT) or options.timeout expired (spawnSync reports ETIMEDOUT). The label (or cmd[0]) prefixes the underlying error message so you know which invocation failed.","triggerScenarios":"Running the orderfile generator without nm or a C compiler on PATH; CC or NM env vars pointing at nonexistent executables; a workload exceeding WORKLOAD_TIMEOUT_MS, which surfaces here as an ETIMEDOUT error rather than a status code.","commonSituations":"Fresh macOS without Xcode Command Line Tools; slim Linux containers without binutils/build-essential; CI images missing the toolchain; stale CC overrides in the environment.","solutions":["Read the label before the colon to identify which command failed to spawn","Install the missing tool: Xcode Command Line Tools (`xcode-select --install`) on macOS, binutils + a C compiler on Linux","Check CC and NM environment overrides point at real executables (`command -v \"$CC\"`)","If the message says ETIMEDOUT, raise the relevant timeout or investigate why the workload hung"],"exampleFix":"# before (missing toolchain on fresh macOS)\n$ bun scripts/orderfile/generate.ts\nError: nm: spawnSync nm ENOENT\n\n# after\n$ xcode-select --install\n$ bun scripts/orderfile/generate.ts","handlingStrategy":"try-catch","validationCode":"import { spawnSync } from \"node:child_process\";\n\nconst resolvable = (bin) => spawnSync(\"which\", [bin]).status === 0;\nfor (const bin of [process.env.NM || \"nm\", process.env.CC || \"cc\"].filter(Boolean)) {\n  if (!resolvable(bin)) throw new Error(`${bin} not found on PATH — install the toolchain first`);\n}","typeGuard":"function isSpawnError(r: { error?: Error }): r is { error: Error } {\n  return r.error !== undefined;\n}","tryCatchPattern":"try {\n  const r = runCommand([nm, bunProfile]);\n} catch (err) {\n  const msg = String(err);\n  if (msg.includes(\"ENOENT\")) throw new Error(`Missing toolchain binary — install it: ${msg}`);\n  if (msg.includes(\"ETIMEDOUT\")) throw new Error(`Command timed out — raise options.timeout: ${msg}`);\n  throw err;\n}","preventionTips":["Install Xcode CLT / binutils / build-essential in any environment that runs orderfile generation","Prefer explicit CC/NM values over inherited ones; unset stale overrides","Set generous timeouts for symbol-dumping commands (nm on bun prints ~10 MB)"],"tags":["process","spawn","toolchain","timeout","orderfile"],"backgroundTag":null,"analyzedSha":"8c5296ac459e8252d3cd702f3fbcbb0c249d95d5","analyzedAt":"2026-08-16T08:01:58.794Z","schemaVersion":2},"datasetVersion":"2026-08-16T08:17:34.114Z"}