From 1c677c9577c6d8acdce329bba371c849f1511424 Mon Sep 17 00:00:00 2001 From: George Padley Date: Thu, 21 Sep 2023 19:17:44 +0100 Subject: [PATCH] Map `DirectoryNotFound` to `FileNotFound` for `open` command (#10089) # Description This PR should close #10085 Maps `DirectoryNotFound` errors to `FileNotFound`. All other errors are left unchanged. # User-Facing Changes This means a user will see `FileNotFound` instead of `DirectoryNotFound` which is more meaning full to the user. --- crates/nu-command/src/filesystem/open.rs | 8 +++++++- crates/nu-command/tests/commands/open.rs | 2 +- 2 files changed, 8 insertions(+), 2 deletions(-) diff --git a/crates/nu-command/src/filesystem/open.rs b/crates/nu-command/src/filesystem/open.rs index 94ac2ff9a..a1d0ca241 100644 --- a/crates/nu-command/src/filesystem/open.rs +++ b/crates/nu-command/src/filesystem/open.rs @@ -103,7 +103,13 @@ impl Command for Open { let arg_span = path.span; // let path_no_whitespace = &path.item.trim_end_matches(|x| matches!(x, '\x09'..='\x0d')); - for path in nu_engine::glob_from(&path, &cwd, call_span, None)?.1 { + for path in nu_engine::glob_from(&path, &cwd, call_span, None) + .map_err(|err| match err { + ShellError::DirectoryNotFound(span, _) => ShellError::FileNotFound(span), + _ => err, + })? + .1 + { let path = path?; let path = Path::new(&path); diff --git a/crates/nu-command/tests/commands/open.rs b/crates/nu-command/tests/commands/open.rs index 05dd4fe9d..5a1b3b2e9 100644 --- a/crates/nu-command/tests/commands/open.rs +++ b/crates/nu-command/tests/commands/open.rs @@ -169,7 +169,7 @@ fn errors_if_file_not_found() { // // This seems to be not directly affected by localization compared to the OS // provided error message - let expected = "not found"; + let expected = "File not found"; assert!( actual.err.contains(expected),