{"record":{"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":"error","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/eb98b54bc9f3c74519f43d066cb3fd02ebc88df0/src/workspace/global_cache_tracker.rs#L663-L699","documentation":"`read_dir_with_filter` lists a directory, returning the names of entries passing a caller-supplied filter. It calls `path.read_dir()`; if the result is `Err`, it inspects the error kind: `NotFound` is tolerated and returns an empty `Vec` (the directory simply is not there), but any other I/O error (permissions, broken symlink, I/O failure) is wrapped with `.context(format!(\"failed to read path `{path:?}`\"))` and propagated. This distinguishes 'absent cache dir' (normal) from 'unreadable cache dir' (real failure).","triggerScenarios":"Global cache tracking enumerating a cargo cache directory (`read_dir`) where the call fails with an error kind other than `NotFound` — e.g. `PermissionDenied`, a broken symlink, or a low-level I/O error. The non-NotFound arm fires.","commonSituations":"Corrupted cache directories, permission/ownership issues on `~/.cargo` subdirs (e.g. after running with sudo), dangling symlinks left by interrupted downloads, or disk/filesystem errors during `cargo cache`/cache cleanup operations.","solutions":["Fix permissions/ownership on the path reported (`sudo chown -R $USER:$USER ~/.cargo` or equivalent).","Remove or recreate a corrupted/broken-symlink cache directory so Cargo can rebuild it.","If the underlying disk/filesystem is failing, address the hardware/fs error, then re-run."],"exampleFix":"# before — unreadable cache dir\n$ ls ~/.cargo/registry/cache\nls: cannot open: Permission denied\n$ cargo cache  # -> failed to read path\n\n# after\n$ sudo chown -R $USER:$USER ~/.cargo\n$ cargo cache","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(),\n        Err(_) => false,\n    }\n}\n// before cache operations, confirm the dir exists and is readable\n","typeGuard":null,"tryCatchPattern":"match path.read_dir() {\n    Ok(entries) => { /* proceed */ }\n    Err(e) if e.kind() == std::io::ErrorKind::NotFound => { /* treat as empty */ }\n    Err(e) => {\n        // permissions/symlink/io failure — surface to user for remediation\n        return Err(anyhow::Error::new(e).context(format!(\"failed to read path `{path:?}`\")));\n    }\n}","preventionTips":["Maintain consistent ownership of `~/.cargo` (avoid sudo writes).","Periodically clean corrupted cache dirs so Cargo can rebuild them.","Monitor disk health; treat recurring non-NotFound read_dir errors as fs warnings."],"tags":["cache","io","permissions","global-cache","cargo"],"backgroundTag":null,"analyzedSha":"eb98b54bc9f3c74519f43d066cb3fd02ebc88df0","analyzedAt":"2026-08-11T17:42:36.556Z","contentChangedAt":"2026-08-11T17:42:36.556Z","schemaVersion":2},"datasetVersion":"2026-09-23T08:17:48.524Z"}