{"id":"f1413f5886f863c3","repo":"rust-lang/cargo","slug":"the-path-was-not-found","errorCode":null,"errorMessage":"the path was not found","messagePattern":"the path was not found","errorType":"exception","errorClass":"io::Error","httpStatus":null,"severity":"error","filePath":"src/util/mod.rs","lineNumber":159,"sourceCode":"}\n\n#[cfg(not(windows))]\n#[inline]\npub fn try_canonicalize<P: AsRef<Path>>(path: P) -> std::io::Result<PathBuf> {\n    std::fs::canonicalize(&path)\n}\n\n#[cfg(windows)]\n#[inline]\npub fn try_canonicalize<P: AsRef<Path>>(path: P) -> std::io::Result<PathBuf> {\n    use std::io::Error;\n    use std::io::ErrorKind;\n\n    // On Windows `canonicalize` may fail, so we fall back to getting an absolute path.\n    std::fs::canonicalize(&path).or_else(|_| {\n        // Return an error if a file does not exist for better compatibility with `canonicalize`\n        if !path.as_ref().try_exists()? {\n            return Err(Error::new(ErrorKind::NotFound, \"the path was not found\"));\n        }\n        std::path::absolute(&path)\n    })\n}\n\n/// Get the current [`umask`] value.\n///\n/// [`umask`]: https://man7.org/linux/man-pages/man2/umask.2.html\n#[cfg(unix)]\npub fn get_umask() -> u32 {\n    use std::sync::OnceLock;\n    static UMASK: OnceLock<libc::mode_t> = OnceLock::new();\n    // SAFETY: Syscalls are unsafe. Calling `umask` twice is even unsafer for\n    // multithreading program, since it doesn't provide a way to retrieve the\n    // value without modifications. We use a static `OnceLock` here to ensure\n    // it only gets call once during the entire program lifetime.\n    *UMASK.get_or_init(|| unsafe {\n        let umask = libc::umask(0o022);","sourceCodeStart":141,"sourceCodeEnd":177,"githubUrl":"https://github.com/rust-lang/cargo/blob/0e07a155371a6ce88ae53a2c00df940280c09a67/src/util/mod.rs#L141-L177","documentation":"Windows-only. In `try_canonicalize` (src/util/mod.rs:159), when `std::fs::canonicalize` fails AND the fallback `path.try_exists()?` returns `false`, cargo synthesizes an `io::Error` with kind `NotFound` and this message so that callers see a consistent NotFound error similar to `canonicalize`'s behaviour on other platforms.","triggerScenarios":"Calling `cargo::util::try_canonicalize(p)` on Windows where `canonicalize` fails (e.g. due to the file living on a UNC/share path or a drive canonicalization quirk) and the path does not actually exist on disk.","commonSituations":"Windows builds referencing a path that was never created or was deleted (stale lockfile, missing vendored dir); case-sensitivity mismatches; mapped network drives disconnected; junction/symlink targets missing.","solutions":["Confirm the path exists and is accessible from the working directory (`Test-Path`, `dir`).","Fix the manifest/config path that referenced the missing file or directory.","Re-create the resource (re-run `cargo vendor`, restore the checkout, remount the share)."],"exampleFix":"# before — vendored dir missing on Windows\n[dependencies]\nfoo = { path = \"vendor/foo\" }   # vendor/ deleted\n# after — regenerate vendor dir\ncargo vendor vendor\n# or correct the path","handlingStrategy":"validation","validationCode":"use std::path::Path;\nfn exists_or_bail(p: &Path) -> std::io::Result<()> {\n    if p.try_exists().unwrap_or(false) { Ok(()) } else { Err(std::io::Error::new(std::io::ErrorKind::NotFound, \"missing\")) }\n}\n// call exists_or_bail(path) before try_canonicalize on Windows","typeGuard":null,"tryCatchPattern":"match cargo::util::try_canonicalize(&p) {\n    Err(e) if e.kind() == std::io::ErrorKind::NotFound => { /* create or fix path */ }\n    res => res,\n}","preventionTips":["Verify referenced paths exist before invoking cargo on Windows.","Keep vendored dirs and checkouts materialized.","Re-run `cargo vendor` if the vendor dir is missing."],"tags":["cargo","windows","canonicalize","path","not-found"],"analyzedSha":"0e07a155371a6ce88ae53a2c00df940280c09a67","analyzedAt":"2026-08-06T01:46:58.334Z","schemaVersion":2}