{"record":{"id":"1c2037ecdd73ba40","repo":"BoundaryML/baml","slug":"failed-to-exec-err-origin","errorCode":null,"errorMessage":"failed to exec {}: {err}{origin}","messagePattern":"failed to exec (.+?): (.+?)(.+?)","errorType":"console","errorClass":null,"httpStatus":null,"severity":"critical","filePath":"baml_language/crates/baml/src/main.rs","lineNumber":498,"sourceCode":"    verify_path_toolchain(cli, &origin)?;\n    reject_self_exec(cli, &origin)?;\n\n    let mut command = Command::new(cli);\n    command.args(args);\n    command.env(\"BAML_WRAPPER_EXEC\", \"1\");\n    // Deliberately not BAML_WRAPPER_RESOLVED_TOOLCHAIN: that carries a version,\n    // and a local build has none. A separate variable also lets the toolchain\n    // binary tell the two situations apart, which `baml ide install` needs.\n    command.env(\"BAML_WRAPPER_LOCAL_TOOLCHAIN\", cli);\n\n    // Anything verify_path_toolchain could not rule out (wrong architecture,\n    // a noexec mount, a missing interpreter) surfaces here, so this message\n    // carries the attribution too.\n    #[cfg(unix)]\n    {\n        use std::os::unix::process::CommandExt;\n        let err = command.exec();\n        Err(anyhow!(\"failed to exec {}: {err}{origin}\", cli.display()))\n    }\n    #[cfg(not(unix))]\n    {\n        let status = command\n            .status()\n            .map_err(|err| anyhow!(\"failed to run {}: {err}{origin}\", cli.display()))?;\n        Ok(status.code().unwrap_or(1))\n    }\n}\n\nfn active_selector() -> Result<ResolvedSelector> {\n    if let Ok(value) = env::var(\"BAML_VERSION\") {\n        if !value.trim().is_empty() {\n            return Ok(ResolvedSelector {\n                selector: normalize_selector(value.trim(), &env::current_dir()?),\n                source: SelectorSource::Env,\n            });\n        }","sourceCodeStart":480,"sourceCodeEnd":516,"githubUrl":"https://github.com/BoundaryML/baml/blob/bd85ce9dee1463ff04d27efd20531013a4ff46c1/baml_language/crates/baml/src/main.rs#L480-L516","documentation":"After `pass_through` resolves a toolchain-specific CLI binary (`cli` path) and attributes it (`origin`), it execs it on Unix. If the exec syscall fails — the binary is missing, not executable, has a broken interpreter/shebang, or lives on a noexec mount — this error is thrown with the binary path, the io::Error, and the origin annotation identifying which toolchain provided it.","triggerScenarios":"Running any `baml` command that dispatches into an active toolchain binary where exec fails: toolchain deleted/moved after pinning, exec bit stripped, corrupted download, incompatible binary for the CPU/OS, or noexec mount.","commonSituations":"Pinning a toolchain path that was later removed, partial downloads from a custom `--manifest-base-url` mirror, cross-architecture toolchain installs (e.g. x86_64 binary on Apple Silicon without Rosetta), noexec NAS/home mounts, or hardlink/symlink targets deleted.","solutions":["Read the `{origin}` suffix to identify which toolchain binary failed, then verify it exists and is executable: `ls -l <path>`.","Reinstall the offending toolchain: `baml toolchain install <version> --force`.","Switch to a known-good toolchain: `baml toolchain use canary` or a previously working version.","Check the filesystem mount for noexec and the binary architecture with `file <path>`.","Inspect the wrapped io::Error (ENOENT/EACCES/ENOEXEC) to pinpoint whether the path, permissions, or format is the problem."],"exampleFix":"# before (pinned toolchain binary deleted)\n$ baml generate\nerror: failed to exec /home/u/.baml/toolchains/0.199.0/bin/baml-cli: No such file or directory (os error 2) (pinned via toolchain manifest)\n\n# after\n$ baml toolchain install 0.199.0 --force\n$ baml generate","handlingStrategy":"try-catch","validationCode":"import os, stat, subprocess\ndef check_toolchain_binary():\n    out = subprocess.run([\"baml\", \"toolchain\", \"list\"], capture_output=True, text=True)\n    # confirm the active/pinned toolchain path exists and is executable before dispatch\n    for line in out.stdout.splitlines():\n        if line.startswith(\"*\") and \"/bin/baml-cli\" in line:\n            p = line.split()[-1]\n            if not os.path.exists(p):\n                raise SystemExit(f\"active toolchain binary missing: {p} — reinstall with `baml toolchain install --force`\")\n            if not (os.stat(p).st_mode & stat.S_IXUSR):\n                raise SystemExit(f\"not executable: {p}\")","typeGuard":"function canExec(p: string): boolean {\n  try { fs.accessSync(p, fs.constants.X_OK); return true; } catch { return false; }\n}","tryCatchPattern":"result = subprocess.run([\"baml\"] + args, capture_output=True)\nif result.returncode != 0 and \"failed to exec\" in result.stderr.decode():\n    msg = result.stderr.decode()\n    origin = msg.split(\"(\")[-1]  # attribution of which toolchain supplied the binary\n    print(f\"Toolchain binary unusable ({origin}); switching to known-good and reinstalling\")\n    subprocess.run([\"baml\", \"toolchain\", \"use\", \"canary\"], check=True)","preventionTips":["After deleting/moving a toolchain directory, re-pin or `toolchain use` a valid one immediately.","When using --manifest-base-url mirrors, verify downloads complete and checksums pass before switching.","Match toolchain architecture to your host (check with `file <binary>`), especially on Apple Silicon.","Avoid placing toolchains on noexec mounts; verify with `mount`.","Keep a known-good toolchain installed as a fallback (`toolchain use canary`)."],"tags":["exec","process","unix","toolchain"],"backgroundTag":"exec-failed","analyzedSha":"bd85ce9dee1463ff04d27efd20531013a4ff46c1","analyzedAt":"2026-09-12T03:38:25.718Z","contentChangedAt":"2026-09-12T03:38:25.718Z","schemaVersion":2},"datasetVersion":"2026-09-14T05:17:10.506Z"}