{"record":{"id":"3807dda6e649f253","repo":"rust-lang/rust","slug":"error-unable-to-find-a-config-file-for-the-given","errorCode":null,"errorMessage":"Error: unable to find a config file for the given path: `{}`","messagePattern":"Error: unable to find a config file for the given path: `(.+?)`","errorType":"exception","errorClass":"io::Error","httpStatus":null,"severity":"error","filePath":"src/tools/rustfmt/src/config/mod.rs","lineNumber":524,"sourceCode":"            // `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        ))\n    };\n\n    // Read the config_path and convert to parent dir if a file is provided.\n    // If a config file cannot be found from the given path, return error.\n    match options.config_path() {\n        Some(path) if !path.exists() => config_path_not_found(path.to_str().unwrap()),\n        Some(path) if path.is_dir() => {\n            let config_file_path = get_toml_path(path)?;\n            if config_file_path.is_some() {\n                Ok(config_file_path)\n            } else {\n                config_path_not_found(path.to_str().unwrap())","sourceCodeStart":506,"sourceCodeEnd":542,"githubUrl":"https://github.com/rust-lang/rust/blob/7088e4b63a9516ebfbfe2ab2d999cf01a528ac14/src/tools/rustfmt/src/config/mod.rs#L506-L542","documentation":"Returned by rustfmt's config_path resolver when the user passes --config-path pointing at a path that either does not exist, or is a directory containing no rustfmt.toml/.rustfmt.toml. ErrorKind::NotFound with the offending path interpolated. It fires from config_path_not_found for both the non-existent-file case and the directory-without-config case.","triggerScenarios":"Running `rustfmt --config-path <p>` where <p> does not exist, or where <p> is a directory that contains neither rustfmt.toml nor .rustfmt.toml. get_toml_path returns None for the directory and config_path_not_found raises the error.","commonSituations":"Typo in --config-path; pointing at a file that was deleted/moved; expecting a config in a directory that does not have one; relative path resolved against an unexpected working directory.","solutions":["Verify the path exists: `ls -l <path>` from the same working directory rustfmt uses.","If passing a directory, add a rustfmt.toml (or .rustfmt.toml) inside it.","If passing a file, ensure the filename is correct and the file is readable.","Drop --config-path to let rustfmt auto-discover, or create the config with `rustfmt --print-default-config > rustfmt.toml`."],"exampleFix":"# before\nrustfmt --config-path ./confg/rustfmt.toml src/lib.rs   # typo\n\n# after\nrustfmt --config-path ./config/rustfmt.toml src/lib.rs","handlingStrategy":"validation","validationCode":"fn config_path_valid(p: &std::path::Path) -> io::Result<()> {\n    if !p.exists() {\n        return Err(io::Error::new(io::ErrorKind::NotFound, format!(\"missing: {p:?}\")));\n    }\n    if p.is_dir() {\n        let has = [\"rustfmt.toml\", \".rustfmt.toml\"].iter().any(|n| p.join(n).is_file());\n        if !has { return Err(io::Error::new(io::ErrorKind::NotFound, \"no config in dir\")); }\n    }\n    Ok(())\n}","typeGuard":null,"tryCatchPattern":"match config_path(opts) {\n    Ok(p) => Ok(p),\n    Err(e) if e.kind() == io::ErrorKind::NotFound\n        && e.to_string().contains(\"unable to find a config file\") => {\n        // correct --config-path or create the file\n        Err(e)\n    }\n    Err(e) => Err(e),\n}","preventionTips":["Verify --config-path exists from rustfmt's working directory before running.","If passing a directory, ensure it contains rustfmt.toml or .rustfmt.toml.","Generate a default config with `rustfmt --print-default-config > rustfmt.toml`."],"tags":["rustfmt","config","path","cli","not-found"],"backgroundTag":null,"analyzedSha":"7088e4b63a9516ebfbfe2ab2d999cf01a528ac14","analyzedAt":"2026-08-10T14:17:03.603Z","contentChangedAt":null,"schemaVersion":2},"datasetVersion":"2026-09-14T05:17:10.506Z"}