{"record":{"id":"b82c2be9fd86cceb","repo":"oven-sh/bun","slug":"failed-to-exec-exe","errorCode":null,"errorMessage":"Failed to exec ${exe}","messagePattern":"Failed to exec (.+?)","errorType":"exception","errorClass":"BuildError","httpStatus":null,"severity":"error","filePath":"scripts/build.ts","lineNumber":299,"sourceCode":"      // it's not obvious ninja finished vs. stalled. This disambiguates.\n      // Targets named when explicit so it's clear what was actually built.\n      const what = args.ninjaTargets.length > 0 ? ` ${args.ninjaTargets.map(t => nameColor(t)).join(\", \")}` : \"\";\n      status(`[build]${what} done`);\n      process.exit(0);\n    }\n\n    // Exec the built binary. result.output.exe is the linked (unstripped)\n    // binary — bun-debug for debug, bun-profile for release. That's the one\n    // you want for dev iteration (has symbols + assertions in debug).\n    const exe = result.output.exe;\n    if (exe === undefined) {\n      throw new BuildError(\"Cannot exec: build mode produced no executable\", {\n        hint: `mode=${result.cfg.mode} builds artifacts, not a runnable binary. Drop the positional args or use --profile=debug.`,\n      });\n    }\n    const child = spawnSync(exe, args.execArgs, { stdio: \"inherit\" });\n    if (child.error) {\n      throw new BuildError(`Failed to exec ${exe}`, { cause: child.error });\n    }\n    // Signal death: re-raise so our parent sees the same signal (shells\n    // show \"Segmentation fault\" etc. based on this, not exit code).\n    if (child.signal) {\n      process.kill(process.pid, child.signal);\n      return;\n    }\n    process.exit(child.status ?? 0);\n  }\n}\n\n/**\n * When an HTTP proxy is configured, cargo's `-Zbuild-std` (release lolhtml)\n * must reach crates.io. Some CI/corporate proxies 403 CONNECT to package\n * registries while direct egress is open. If a proxy is set and crates.io\n * isn't already exempted, probe direct connectivity once: if it works, add\n * crates.io to NO_PROXY so cargo goes direct. If the probe fails (mandatory-\n * egress-proxy topology, firewall drops direct), leave NO_PROXY untouched so","sourceCodeStart":281,"sourceCodeEnd":317,"githubUrl":"https://github.com/oven-sh/bun/blob/8c5296ac459e8252d3cd702f3fbcbb0c249d95d5/scripts/build.ts#L281-L317","documentation":"scripts/build.ts spawns the just-linked binary with spawnSync and throws this BuildError when the spawn itself errors (child.error set) — the binary could not be launched at all, before any code inside it ran. The original error (ENOENT, EACCES, etc.) is attached as cause.","triggerScenarios":"ENOENT because result.output.exe points to a path that was not produced or was removed (partial build, pruned build dir), EACCES/EPERM from a missing execute bit, or the OS refusing to run the binary (loader mismatch, quarantine).","commonSituations":"Build dir cleaned or moved between link and exec; disk full so linking truncated the binary; filesystems that strip the exec bit (network mounts, WSL interop); a cross-compiled binary that does not match the host.","solutions":["Check the exe path in the message exists and is executable (ls -l)","Rebuild cleanly: remove the build dir and run bun bd again","Fix permissions or move the repo off a filesystem that strips the exec bit","Verify the profile matches the host (no cross-compile profile combined with exec args)"],"exampleFix":null,"handlingStrategy":"try-catch","validationCode":"import { existsSync, accessSync, constants } from \"node:fs\";\n// after the build resolves but before exec\nif (!existsSync(exe)) throw new Error(`build output missing: ${exe}`);\naccessSync(exe, constants.X_OK); // throws if not executable","typeGuard":null,"tryCatchPattern":"try {\n  const child = spawnSync(exe, execArgs, { stdio: \"inherit\" });\n  if (child.error) throw new BuildError(`Failed to exec ${exe}`, { cause: child.error });\n} catch (e) {\n  const code = e.cause?.code;\n  if (code === \"ENOENT\") { /* rebuild then retry once */ }\n  else if (code === \"EACCES\") { /* fix the exec bit / filesystem */ }\n  else throw e;\n}","preventionTips":["Do not delete or move build-dir artifacts while a build-then-exec command runs","On unusual filesystems, verify the exec bit after linking","Treat ENOENT on a fresh binary as rebuild-needed, not a runtime bug"],"tags":["build","spawn","exec","filesystem"],"backgroundTag":null,"analyzedSha":"8c5296ac459e8252d3cd702f3fbcbb0c249d95d5","analyzedAt":"2026-08-16T08:01:58.794Z","schemaVersion":2},"datasetVersion":"2026-08-16T08:17:34.114Z"}