From f122065772946b69fc4c6f31a266ac8a65be18e6 Mon Sep 17 00:00:00 2001 From: Darren Schroeder <343840+fdncred@users.noreply.github.com> Date: Tue, 13 Aug 2024 18:40:17 -0500 Subject: [PATCH] create a better error message for bad glob patterns (#13613) # Description @sholderbach pointed out that I could've made this error message better. So, here's my attempt to make it better. This should work. I had a hard time figuring out how to trigger the error anyway because the type checker doesn't allow "bad" parameters to begin with. ### Before ![image](https://github.com/user-attachments/assets/ac60ce27-4b9a-49ca-910c-74422ae31bc4) ### After ![image](https://github.com/user-attachments/assets/fe939339-67df-4d30-a8dd-5ce3fe623a95) # User-Facing Changes # Tests + Formatting # After Submitting --- crates/nu-command/src/filesystem/glob.rs | 65 ++++++++++++------------ 1 file changed, 33 insertions(+), 32 deletions(-) diff --git a/crates/nu-command/src/filesystem/glob.rs b/crates/nu-command/src/filesystem/glob.rs index 8d910e15d5..2976c765a2 100644 --- a/crates/nu-command/src/filesystem/glob.rs +++ b/crates/nu-command/src/filesystem/glob.rs @@ -148,40 +148,41 @@ impl Command for Glob { } }; - let glob_pattern = match glob_pattern_input { - Value::String { val, .. } => { - if val.is_empty() { - return Err(ShellError::GenericError { - error: "glob pattern must not be empty".into(), - msg: "glob pattern is empty".into(), - span: Some(glob_span), - help: Some("add characters to the glob pattern".into()), - inner: vec![], - }); - } else { - val + let glob_pattern = + match glob_pattern_input { + Value::String { val, .. } => { + if val.is_empty() { + return Err(ShellError::GenericError { + error: "glob pattern must not be empty".into(), + msg: "glob pattern is empty".into(), + span: Some(glob_span), + help: Some("add characters to the glob pattern".into()), + inner: vec![], + }); + } else { + val + } } - } - Value::Glob { val, .. } => { - if val.is_empty() { - return Err(ShellError::GenericError { - error: "glob pattern must not be empty".into(), - msg: "glob pattern is empty".into(), - span: Some(glob_span), - help: Some("add characters to the glob pattern".into()), - inner: vec![], - }); - } else { - val + Value::Glob { val, .. } => { + if val.is_empty() { + return Err(ShellError::GenericError { + error: "glob pattern must not be empty".into(), + msg: "glob pattern is empty".into(), + span: Some(glob_span), + help: Some("add characters to the glob pattern".into()), + inner: vec![], + }); + } else { + val + } } - } - _ => { - return Err(ShellError::IncompatibleParametersSingle { - msg: "Incorrect parameter type".to_string(), - span: glob_span, - }) - } - }; + _ => return Err(ShellError::IncorrectValue { + msg: "Incorrect glob pattern supplied to glob. Please use string or glob only." + .to_string(), + val_span: call.head, + call_span: glob_span, + }), + }; let folder_depth = if let Some(depth) = depth { depth