From 1bc1bb611130ea624b014cba99704ea165bd45f6 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Andr=C3=A9s=20N=2E=20Robalino?= Date: Thu, 1 Aug 2019 16:55:49 -0500 Subject: [PATCH] Glob paths can fail. Communicates the error if it happens. thanks (jonathandturner) --- src/commands/rm.rs | 10 +++++++++- tests/commands_test.rs | 16 ++++++++-------- 2 files changed, 17 insertions(+), 9 deletions(-) diff --git a/src/commands/rm.rs b/src/commands/rm.rs index 51a08ec6e2..51dc9b6e91 100644 --- a/src/commands/rm.rs +++ b/src/commands/rm.rs @@ -45,7 +45,15 @@ pub fn rm(args: CommandArgs) -> Result { file => full_path.push(file), } - for entry in glob(&full_path.to_string_lossy()).expect("Failed to read glob pattern") { + let entries = glob(&full_path.to_string_lossy()); + + if entries.is_err() { + return Err(ShellError::string("Invalid pattern.")); + } + + let entries = entries.unwrap(); + + for entry in entries { match entry { Ok(path) => { if path.is_dir() { diff --git a/tests/commands_test.rs b/tests/commands_test.rs index 606cd49039..a1699a8d85 100644 --- a/tests/commands_test.rs +++ b/tests/commands_test.rs @@ -88,14 +88,14 @@ fn save_figures_out_intelligently_where_to_write_out_with_metadata() { .with_files(vec![FileWithContent( "cargo_sample.toml", r#" - [package] - name = "nu" - version = "0.1.1" - authors = ["Yehuda Katz "] - description = "A shell for the GitHub era" - license = "ISC" - edition = "2018" - "#, + [package] + name = "nu" + version = "0.1.1" + authors = ["Yehuda Katz "] + description = "A shell for the GitHub era" + license = "ISC" + edition = "2018" + "#, )]) .test_dir_name();