Skip to content

Commit 9d4d5c9

Browse files
committed
Allow NotADirectory errors in config lookup
Users may have files where directories are expected, such as "$HOME/.config" being a file when trying to lookup "$HOME/.config/rustfmt/.rustfmt.toml". We don't want to treat such situations as errors.
1 parent acf51c8 commit 9d4d5c9

File tree

1 file changed

+5
-3
lines changed

1 file changed

+5
-3
lines changed

src/config/mod.rs

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -499,10 +499,12 @@ fn get_toml_path(dir: &Path) -> Result<Option<PathBuf>, Error> {
499499
// Only return if it's a file to handle the unlikely situation of a directory named
500500
// `rustfmt.toml`.
501501
Ok(ref md) if md.is_file() => return Ok(Some(config_file.canonicalize()?)),
502-
// Return the error if it's something other than `NotFound`; otherwise we didn't
503-
// find the project file yet, and continue searching.
502+
// We didn't find the project file yet, and continue searching if:
503+
// `NotFound` => file not found
504+
// `NotADirectory` => rare case where expected directory is a file
505+
// Otherwise, return the error
504506
Err(e) => {
505-
if e.kind() != ErrorKind::NotFound {
507+
if !matches!(e.kind(), ErrorKind::NotFound | ErrorKind::NotADirectory) {
506508
let ctx = format!("Failed to get metadata for config file {:?}", &config_file);
507509
let err = anyhow::Error::new(e).context(ctx);
508510
return Err(Error::new(ErrorKind::Other, err));

0 commit comments

Comments
 (0)