{"id":"dd14c5d606f98645","repo":"rust-lang/cargo","slug":"failed-to-read-path-path","errorCode":null,"errorMessage":"failed to read path `{path:?}`","messagePattern":"failed to read path `(.+?)`","errorType":"exception","errorClass":"anyhow::Error","httpStatus":null,"severity":"warning","filePath":"src/workspace/global_cache_tracker.rs","lineNumber":681,"sourceCode":"    fn list_dir_names(path: &Path) -> CargoResult<Vec<String>> {\n        Self::read_dir_with_filter(path, &|entry| {\n            entry.file_type().map_or(false, |ty| ty.is_dir())\n        })\n    }\n\n    /// Returns a list of names in a directory, filtered by the given callback.\n    fn read_dir_with_filter(\n        path: &Path,\n        filter: &dyn Fn(&std::fs::DirEntry) -> bool,\n    ) -> CargoResult<Vec<String>> {\n        let entries = match path.read_dir() {\n            Ok(e) => e,\n            Err(e) => {\n                if e.kind() == std::io::ErrorKind::NotFound {\n                    return Ok(Vec::new());\n                } else {\n                    return Err(\n                        anyhow::Error::new(e).context(format!(\"failed to read path `{path:?}`\"))\n                    );\n                }\n            }\n        };\n        let names = entries\n            .filter_map(|entry| entry.ok())\n            .filter(|entry| filter(entry))\n            .filter_map(|entry| entry.file_name().into_string().ok())\n            .collect();\n        Ok(names)\n    }\n\n    /// Synchronizes the database to match the files on disk.\n    ///\n    /// This performs the following cleanups:\n    ///\n    /// 1. Remove entries from the database that are missing on disk.\n    /// 2. Adds missing entries to the database that are on disk (such as when","sourceCodeStart":663,"sourceCodeEnd":699,"githubUrl":"https://github.com/rust-lang/cargo/blob/0e07a155371a6ce88ae53a2c00df940280c09a67/src/workspace/global_cache_tracker.rs#L663-L699","documentation":"Raised in `GlobalCacheTracker::read_dir_with_filter` (src/workspace/global_cache_tracker.rs:680) when `path.read_dir()` fails with an io::Error whose kind is NOT `NotFound` (NotFound is tolerated and returns an empty vec). Any other IO failure — permission denied, broken symlink, I/O error — is wrapped with `failed to read path \\\"<path>\\\"` context.","triggerScenarios":"`cargo cache` / global cache tracking walks a directory under `$CARGO_HOME` (e.g. `registry/cache`, `git/db`) and `read_dir` returns a non-NotFound error: EACCES on a dir cargo cannot traverse, EIO, a broken symlink target, or a filesystem error.","commonSituations":"Permissions on `~/.cargo` set so some subdirs are not readable by the cargo user; partial extraction leaving broken symlinks; NFS/share hiccups; another process modifying the cache concurrently; disk errors.","solutions":["Fix permissions so cargo can read the directory (`chmod -R u+rX ~/.cargo`).","Remove broken symlinks or corrupt cache entries (`cargo cache clean` or manual cleanup of the named path).","Ensure no other process is mutating `$CARGO_HOME` while cargo runs; retry if it was transient (I/O error)."],"exampleFix":"# grant read+execute on the offending cache dir\nchmod -R u+rX ~/.cargo/registry/cache\n# or clean a corrupt cache\ncargo cache clean","handlingStrategy":"try-catch","validationCode":"use std::path::Path;\nfn readable_dir(p: &Path) -> bool {\n    match std::fs::metadata(p) {\n        Ok(m) => m.is_dir() && std::fs::read_dir(p).is_ok(),\n        Err(_) => false,\n    }\n}\n// before cache operations, verify readable_dir on $CARGO_HOME subdirs","typeGuard":null,"tryCatchPattern":"// treat non-NotFound read_dir errors as best-effort skips\nlet names = match path.read_dir() {\n    Ok(e) => e.filter_map(|r| r.ok()).map(|e| e.file_name().to_string_lossy().into_owned()).collect::<Vec<_>>(),\n    Err(e) if e.kind() == std::io::ErrorKind::NotFound => Vec::new(),\n    Err(_) => Vec::new(), // swallow permission/IO errors instead of failing\n};","preventionTips":["Run cargo as the owner of $CARGO_HOME; fix permissions with chmod -R u+rX.","Avoid concurrent mutating access to the cargo cache.","Periodically clean corrupt cache entries."],"tags":["cargo","cache","io","filesystem","permissions"],"analyzedSha":"0e07a155371a6ce88ae53a2c00df940280c09a67","analyzedAt":"2026-08-06T01:46:58.334Z","schemaVersion":2}