{"record":{"id":"c0c0afa87a84418b","repo":"rust-lang/rust","slug":"failed-to-get-metadata-for-config-file","errorCode":null,"errorMessage":"Failed to get metadata for config file {:?}","messagePattern":"Failed to get metadata for config file (.+?)","errorType":"exception","errorClass":"anyhow::Error","httpStatus":null,"severity":"error","filePath":"src/tools/rustfmt/src/config/mod.rs","lineNumber":512,"sourceCode":"// Check for the presence of known config file names (`rustfmt.toml`, `.rustfmt.toml`) in `dir`\n//\n// Return the path if a config file exists, empty if no file exists, and Error for IO errors\nfn get_toml_path(dir: &Path) -> Result<Option<PathBuf>, Error> {\n    const CONFIG_FILE_NAMES: [&str; 2] = [\".rustfmt.toml\", \"rustfmt.toml\"];\n    for config_file_name in &CONFIG_FILE_NAMES {\n        let config_file = dir.join(config_file_name);\n        match fs::metadata(&config_file) {\n            // Only return if it's a file to handle the unlikely situation of a directory named\n            // `rustfmt.toml`.\n            Ok(ref md) if md.is_file() => return Ok(Some(config_file.canonicalize()?)),\n            // We didn't find the project file yet, and continue searching if:\n            // `NotFound` => file not found\n            // `NotADirectory` => rare case where expected directory is a file\n            // Otherwise, return the error\n            Err(e) => {\n                if !matches!(e.kind(), ErrorKind::NotFound | ErrorKind::NotADirectory) {\n                    let ctx = format!(\"Failed to get metadata for config file {:?}\", &config_file);\n                    let err = anyhow::Error::new(e).context(ctx);\n                    return Err(Error::new(ErrorKind::Other, err));\n                }\n            }\n            _ => {}\n        }\n    }\n    Ok(None)\n}\n\nfn config_path(options: &dyn CliOptions) -> Result<Option<PathBuf>, Error> {\n    let config_path_not_found = |path: &str| -> Result<Option<PathBuf>, Error> {\n        Err(Error::new(\n            ErrorKind::NotFound,\n            format!(\n                \"Error: unable to find a config file for the given path: `{}`\",\n                path\n            ),\n        ))","sourceCodeStart":494,"sourceCodeEnd":530,"githubUrl":"https://github.com/rust-lang/rust/blob/7088e4b63a9516ebfbfe2ab2d999cf01a528ac14/src/tools/rustfmt/src/config/mod.rs#L494-L530","documentation":"Returned by rustfmt's config loader get_toml_path when fs::metadata on a candidate config file (rustfmt.toml / .rustfmt.toml) returns an error other than NotFound or NotADirectory. Those two are treated as 'keep searching'; any other IO error (permission denied, I/O error, etc.) is wrapped with anyhow context naming the config file and rethrown as ErrorKind::Other.","triggerScenarios":"rustfmt searching a directory for rustfmt.toml/.rustfmt.toml where fs::metadata fails for a non-existence reason - e.g. permission denied on the directory or the candidate path, broken symlink, filesystem I/O error, or a race where the path exists but cannot be stat'd.","commonSituations":"Config file on a broken symlink; directory not readable due to permissions; network filesystem hiccup; SELinux/AppArmor denying stat; path is a special device that errors on metadata.","solutions":["Check permissions on the directory and the candidate rustfmt.toml path named in the error.","Resolve broken symlinks pointing at the config file.","Retry on a transient filesystem/network-filesystem error.","Move or rename the problematic config file and let rustfmt generate a fresh default."],"exampleFix":"# before: broken symlink at rustfmt.toml\nls -l rustfmt.toml   # lrwxrwxrwx ... -> /nonexistent\n\n# after\nrm rustfmt.toml\ncp ~/.rustfmt.toml rustfmt.toml","handlingStrategy":"validation","validationCode":"fn config_metadata_ok(p: &std::path::Path) -> io::Result<()> {\n    match std::fs::metadata(p) {\n        Ok(_) => Ok(()),\n        Err(e) if matches!(e.kind(), io::ErrorKind::NotFound | io::ErrorKind::NotADirectory) => Ok(()),\n        Err(e) => Err(e),\n    }\n}","typeGuard":null,"tryCatchPattern":"match get_toml_path(dir) {\n    Ok(p) => Ok(p),\n    Err(e) if e.to_string().contains(\"Failed to get metadata for config file\") => {\n        // fix permissions / symlink on the named path, then retry\n        Err(e)\n    }\n    Err(e) => Err(e),\n}","preventionTips":["Ensure rust-analyzer/cargo has read+stat permission on config dirs.","Avoid broken symlinks for rustfmt.toml.","Retry once on network filesystems where stat can be transient."],"tags":["rustfmt","config","filesystem","permissions","metadata"],"backgroundTag":null,"analyzedSha":"7088e4b63a9516ebfbfe2ab2d999cf01a528ac14","analyzedAt":"2026-08-10T14:17:03.603Z","contentChangedAt":null,"schemaVersion":2},"datasetVersion":"2026-09-14T05:17:10.506Z"}