{"record":{"id":"d1610f7821ef76a2","repo":"tauri-apps/tauri","slug":"failed-to-get-exe-directory","errorCode":null,"errorMessage":"failed to get exe directory","messagePattern":"failed to get exe directory","errorType":"panic","errorClass":null,"httpStatus":null,"severity":"error","filePath":"crates/tauri-utils/src/platform.rs","lineNumber":286,"sourceCode":"  {\n    let exe = current_exe()?;\n    resource_dir_from(exe, package_info, env)\n  }\n}\n\n#[cfg(target_os = \"android\")]\nfn resource_dir_android(_package_info: &PackageInfo, _env: &Env) -> crate::Result<PathBuf> {\n  Ok(PathBuf::from(ANDROID_ASSET_PROTOCOL_URI_PREFIX))\n}\n\n#[cfg(not(target_os = \"android\"))]\n#[allow(unused_variables)]\nfn resource_dir_from<P: AsRef<std::path::Path>>(\n  exe: P,\n  package_info: &PackageInfo,\n  env: &Env,\n) -> crate::Result<PathBuf> {\n  let exe_dir = exe.as_ref().parent().expect(\"failed to get exe directory\");\n  let curr_dir = exe_dir.display().to_string();\n\n  let parts: Vec<&str> = curr_dir.split(std::path::MAIN_SEPARATOR).collect();\n  let len = parts.len();\n\n  // Check if running from the Cargo output directory, which means it's an executable in a development machine\n  // We check if the binary is inside a `target` folder which can be either `target/$profile` or `target/$triple/$profile`\n  // and see if there's a .cargo-lock file along the executable\n  // This ensures the check is safer so it doesn't affect apps in production\n  // Windows also includes the resources in the executable folder so we check that too\n  if cfg!(target_os = \"windows\")\n    || ((len >= 2 && parts[len - 2] == \"target\") || (len >= 3 && parts[len - 3] == \"target\"))\n      && is_cargo_output_directory(exe_dir)\n  {\n    return Ok(exe_dir.to_path_buf());\n  }\n\n  #[allow(unused_mut, unused_assignments)]","sourceCodeStart":268,"sourceCodeEnd":304,"githubUrl":"https://github.com/tauri-apps/tauri/blob/460ec35447493200d64290dd7f015d5a91d0fd58/crates/tauri-utils/src/platform.rs#L268-L304","documentation":"`resource_dir_from` computes the resource directory from the current executable path by taking `exe.as_ref().parent()`, which returns `None` for a bare file name with no parent directory. The `expect` panics with this message in that case. It effectively means the exe path handed to `resource_dir()` has no parent component.","triggerScenarios":"Calling `tauri::path::resource_dir()` (or `resource_dir_from`) when the exe path is a single component like `\"myapp\"` or `\"\"` — no directory separator — so `Path::parent()` yields `None`.","commonSituations":"Running the binary via a bare name resolved through PATH in unusual environments; embedding tauri in tests with a stub exe path like `PathBuf::from(\"app\")`; exotic process launching that reports a relative bare filename.","solutions":["Launch the app via a path that includes its directory (e.g. `./target/debug/myapp` instead of `myapp`)","In tests/custom callers, pass a full absolute path to `resource_dir_from` instead of a bare filename","Use `std::env::current_exe()` to obtain a fully qualified exe path"],"exampleFix":"// before\nresource_dir_from(PathBuf::from(\"myapp\"), &pkg_info, &env)\n// after\nresource_dir_from(std::env::current_exe().unwrap(), &pkg_info, &env)","handlingStrategy":"validation","validationCode":"let exe = std::env::current_exe().unwrap();\nassert!(exe.parent().is_some(), \"exe path must include a directory\");","typeGuard":"fn exe_path_has_parent(exe: &std::path::Path) -> bool {\n  exe.parent().map(|p| !p.as_os_str().is_empty()).unwrap_or(false)\n}","tryCatchPattern":null,"preventionTips":["Always resolve the exe path with `std::env::current_exe()` before computing resource_dir","Avoid launching via bare PATH-resolved names in embedded/test environments","In tests, pass absolute stub paths with a parent directory"],"tags":["filesystem","panic","path-handling","tauri"],"backgroundTag":"missing-required-argument","analyzedSha":"460ec35447493200d64290dd7f015d5a91d0fd58","analyzedAt":"2026-09-18T23:55:51.277Z","contentChangedAt":"2026-09-18T23:55:51.277Z","schemaVersion":2},"datasetVersion":"2026-09-23T08:17:48.524Z"}