Skip to content

Allow NotADirectory errors in config lookup #6624

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
8 changes: 5 additions & 3 deletions src/config/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -500,10 +500,12 @@ fn get_toml_path(dir: &Path) -> Result<Option<PathBuf>, Error> {
// Only return if it's a file to handle the unlikely situation of a directory named
// `rustfmt.toml`.
Ok(ref md) if md.is_file() => return Ok(Some(config_file.canonicalize()?)),
// Return the error if it's something other than `NotFound`; otherwise we didn't
// find the project file yet, and continue searching.
// We didn't find the project file yet, and continue searching if:
// `NotFound` => file not found
// `NotADirectory` => rare case where expected directory is a file
// Otherwise, return the error
Err(e) => {
if e.kind() != ErrorKind::NotFound {
if !matches!(e.kind(), ErrorKind::NotFound | ErrorKind::NotADirectory) {
let ctx = format!("Failed to get metadata for config file {:?}", &config_file);
let err = anyhow::Error::new(e).context(ctx);
return Err(Error::new(ErrorKind::Other, err));
Expand Down
Loading