{"record":{"id":"b83570a94a75c7ed","repo":"rust-lang/cargo","slug":"no-executable-for-found-in-path","errorCode":null,"errorMessage":"no executable for `{}` found in PATH","messagePattern":"no executable for `(.+?)` found in PATH","errorType":"exception","errorClass":null,"httpStatus":null,"severity":"error","filePath":"crates/cargo-util/src/paths.rs","lineNumber":142,"sourceCode":"pub fn resolve_executable(exec: &Path) -> Result<PathBuf> {\n    if exec.components().count() == 1 {\n        let paths = env::var_os(\"PATH\").ok_or_else(|| anyhow::format_err!(\"no PATH\"))?;\n        let candidates = env::split_paths(&paths).flat_map(|path| {\n            let candidate = path.join(&exec);\n            let with_exe = if env::consts::EXE_EXTENSION.is_empty() {\n                None\n            } else {\n                Some(candidate.with_extension(env::consts::EXE_EXTENSION))\n            };\n            iter::once(candidate).chain(with_exe)\n        });\n        for candidate in candidates {\n            if candidate.is_file() {\n                return Ok(candidate);\n            }\n        }\n\n        anyhow::bail!(\"no executable for `{}` found in PATH\", exec.display())\n    } else {\n        Ok(exec.into())\n    }\n}\n\n/// Returns metadata for a file (follows symlinks).\n///\n/// Equivalent to [`std::fs::metadata`] with better error messages.\npub fn metadata<P: AsRef<Path>>(path: P) -> Result<Metadata> {\n    let path = path.as_ref();\n    std::fs::metadata(path)\n        .with_context(|| format!(\"failed to load metadata for path `{}`\", path.display()))\n}\n\n/// Returns metadata for a file without following symlinks.\n///\n/// Equivalent to [`std::fs::metadata`] with better error messages.\npub fn symlink_metadata<P: AsRef<Path>>(path: P) -> Result<Metadata> {","sourceCodeStart":124,"sourceCodeEnd":160,"githubUrl":"https://github.com/rust-lang/cargo/blob/42eee92bc9aa4449f4e25d84e4ceb1cf8e0f87f9/crates/cargo-util/src/paths.rs#L124-L160","documentation":"resolve_executable searches each directory in the PATH environment variable for a file matching the given executable name (appending the platform EXE_EXTENSION if needed). If no candidate is an existing file, it bails with 'no executable for ... found in PATH'. The lookup only runs when the name is a single path component (no separators).","triggerScenarios":"Calling resolve_executable with a bare tool name (e.g. 'rustc', 'git', 'cmake') when that tool is not installed or not on PATH; PATH is empty/unset; the executable lacks the expected extension on Windows.","commonSituations":"Missing build dependency (linker, ar, cmake, git) in CI; container images without the tool installed; wrong PATH in a spawned process; Windows tools missing .exe extension.","solutions":["Install the missing executable and ensure it is on PATH.","Verify PATH contains the install directory: `echo $PATH` / `where <tool>` (Windows) / `which <tool>` (Unix).","Pass an absolute or relative path to the executable instead of a bare name so the PATH search is bypassed.","On Windows, confirm the file has the .exe extension."],"exampleFix":"// before\nresolve_executable(Path::new(\"my-tool\"))  // not on PATH\n// after\nresolve_executable(Path::new(\"/opt/my-tool/bin/my-tool\"))","handlingStrategy":"validation","validationCode":"// Pre-check PATH before resolving\nlet name = \"my-tool\";\nlet found = std::env::var_os(\"PATH\").map(|p| std::env::split_paths(&p)\n    .any(|d| d.join(name).is_file())).unwrap_or(false);\nif !found { eprintln!(\"{name} not on PATH; install it first\"); }","typeGuard":"null","tryCatchPattern":"null","preventionTips":["Verify required tools are installed in CI setup steps.","Prefer absolute paths to bypass PATH ambiguity.","On Windows, account for .exe extension."],"tags":["cargo","path","executable","environment","dependency"],"backgroundTag":null,"analyzedSha":"42eee92bc9aa4449f4e25d84e4ceb1cf8e0f87f9","analyzedAt":"2026-08-11T17:42:36.556Z","contentChangedAt":"2026-08-11T17:42:36.556Z","schemaVersion":2},"datasetVersion":"2026-09-23T08:17:48.524Z"}