Skip to content

Commit 7e17af1

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 0332da0 commit 7e17af1

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

0 commit comments

Comments
 (0)