{"record":{"id":"39722a2b9a35c3e2","repo":"BoundaryML/baml","slug":"cannot-determine-directory-of-current-executable","errorCode":null,"errorMessage":"cannot determine directory of current executable","messagePattern":"cannot determine directory of current executable","errorType":"exception","errorClass":null,"httpStatus":null,"severity":"error","filePath":"baml_language/crates/baml_cli/src/pack_command.rs","lineNumber":560,"sourceCode":"        .collect();\n    hits.sort();\n    hits.dedup();\n    hits.truncate(5);\n    hits\n}\n\nfn canonicalize_function_name(engine: &BexEngine, name: &str) -> String {\n    engine\n        .find_user_function(name)\n        .map(|info| info.qualified_name)\n        .unwrap_or_else(|| name.to_string())\n}\n\nfn read_host_binary(target_triple: &str, reporter: &Reporter) -> Result<Vec<u8>> {\n    let exe = std::env::current_exe().context(\"failed to locate current executable\")?;\n    let dir = exe\n        .parent()\n        .ok_or_else(|| anyhow!(\"cannot determine directory of current executable\"))?;\n    let host_name = host_binary_name(target_triple);\n    let host_path = dir.join(&host_name);\n    let is_native = target_triple == release_host_target_triple()?;\n    if is_native && host_path.exists() {\n        return std::fs::read(&host_path)\n            .with_context(|| format!(\"failed to read {}\", host_path.display()));\n    }\n\n    // A workspace-built host sits next to the CLI but we're skipping it\n    // because the requested `--target` isn't this machine's platform, so we\n    // download a release host for that target instead. Surface it: a dev who\n    // expected their local host embedded would otherwise silently get\n    // released bytes — exactly the kind of skip that hides host-side bugs\n    // from local testing. (No local host => nothing skipped; stay quiet, the\n    // \"Downloading\" line below already explains the fetch.)\n    if !is_native && host_path.exists() {\n        reporter.warning(format_args!(\n            \"ignoring local `{}` (built for this machine) — packing for `{target_triple}` \\","sourceCodeStart":542,"sourceCodeEnd":578,"githubUrl":"https://github.com/BoundaryML/baml/blob/bd85ce9dee1463ff04d27efd20531013a4ff46c1/baml_language/crates/baml_cli/src/pack_command.rs#L542-L578","documentation":"`read_host_binary` locates the bundled host binary next to the currently running `baml` executable. `std::env::current_exe()` succeeded, but `Path::parent()` returned `None`, so the crate cannot determine which directory to look in for the host binary. This is an internal invariant violation: a valid executable path virtually always has a parent directory.","triggerScenarios":"Running `baml pack` which calls `read_host_binary(target_triple, reporter)`; `std::env::current_exe()` returns a path with no parent (e.g. a bare root-level or degenerate path) so `exe.parent()` yields `None` and the `ok_or_else` branch fires.","commonSituations":"The binary was invoked through an exotic exec mechanism that reports a root-like path as the executable (e.g. running the binary as `/baml` at filesystem root, unusual container/namespace setups, or a misbehaving current_exe shim); essentially never seen in normal installs.","solutions":["Check what `baml` reports as its executable path (`which baml`, `type baml`) and reinstall/relaunch it from a normal directory rather than a root-level path.","Reinstall the BAML CLI from an official release so it sits in a standard bin directory (e.g. ~/.local/bin, /usr/local/bin).","If invoked via a wrapper/symlink trick, invoke the real binary path directly instead.","If it persists, file a bug with the OS and invocation details — this is effectively an internal invariant violation in `read_host_binary`."],"exampleFix":"// before\nlet dir = exe\n    .parent()\n    .ok_or_else(|| anyhow!(\"cannot determine directory of current executable\"))?;\n// after (caller-side workaround: install the CLI in a normal location)\n// $ mv ./baml /usr/local/bin/baml && baml pack --target <triple>","handlingStrategy":"try-catch","validationCode":"let exe = std::env::current_exe().context(\"failed to locate current executable\")?;\nif exe.parent().is_none() {\n    return Err(anyhow!(\"executable path {:?} has no parent directory; reinstall the CLI in a normal bin directory\", exe));\n}","typeGuard":"fn has_parent_dir(p: &std::path::Path) -> bool { p.parent().is_some() }","tryCatchPattern":"match read_host_binary(target_triple, &reporter) {\n    Ok(bytes) => use_bytes(bytes),\n    Err(e) if e.to_string().contains(\"cannot determine directory\") => reinstall_cli_and_retry(),\n    Err(e) => report(e),\n}","preventionTips":["Install the CLI in a standard bin directory with a well-formed absolute path.","Avoid launching the binary via mechanisms that may report degenerate executable paths (custom namespaces, root-level binaries).","Prefer official installers/scripts that place the binary and verify `current_exe` resolves sanely."],"tags":["rust","cli","filesystem","executable-path"],"backgroundTag":"internal-invariant-violation","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"}