Compare commits

...

2 Commits

Author SHA1 Message Date
370639d7d7 Fix ls panics when a file or directory not exists (#6148)
* Fix ls panics when a file or directory not exists

Fixes #6146

Signed-off-by: nibon7 <nibon7@163.com>

* add test

Signed-off-by: nibon7 <nibon7@163.com>
2022-07-28 09:16:52 +12:00
d326f6def6 winget wants this to match (#6152)
See the link below for more information
https://github.com/microsoft/winget-pkgs/pull/67598#issuecomment-1196952191
2022-07-28 09:16:14 +12:00
3 changed files with 15 additions and 3 deletions

View File

@ -147,9 +147,13 @@ impl Command for Ls {
Some(glob_options) Some(glob_options)
}; };
let (prefix, paths) = let (prefix, paths) =
nu_engine::glob_from(&glob_path, &cwd, call_span, glob_options) match nu_engine::glob_from(&glob_path, &cwd, call_span, glob_options) {
.expect("glob failure"); Ok((prefix, paths)) => (prefix, paths),
Err(e) => {
shell_errors.push(e);
return Vec::from([Value::nothing(call_span)]).into_iter();
}
};
let mut paths_peek = paths.peekable(); let mut paths_peek = paths.peekable();
if paths_peek.peek().is_none() { if paths_peek.peek().is_none() {
shell_errors.push(ShellError::GenericError( shell_errors.push(ShellError::GenericError(

View File

@ -527,3 +527,11 @@ fn can_list_system_folder() {
)); ));
assert_eq!(ls_with_filter.err, ""); assert_eq!(ls_with_filter.err, "");
} }
#[test]
fn list_a_directory_not_exists() {
Playground::setup("ls_test_directory_not_exists", |dirs, _sandbox| {
let actual = nu!(cwd: dirs.test(), "ls a_directory_not_exists");
assert!(actual.err.contains("directory not found"));
})
}

Binary file not shown.