From cb926f7b49b8c9921f7db881885f76a621e5013c Mon Sep 17 00:00:00 2001 From: Reilly Wood <26268125+rgwood@users.noreply.github.com> Date: Thu, 10 Nov 2022 23:05:09 -0800 Subject: [PATCH] Better error message when rm can't find files (#7098) --- crates/nu-command/src/filesystem/rm.rs | 20 +++++++++++++++++--- 1 file changed, 17 insertions(+), 3 deletions(-) diff --git a/crates/nu-command/src/filesystem/rm.rs b/crates/nu-command/src/filesystem/rm.rs index b0b422b92d..1608d735db 100644 --- a/crates/nu-command/src/filesystem/rm.rs +++ b/crates/nu-command/src/filesystem/rm.rs @@ -197,10 +197,24 @@ fn rm( )); } + let targets_span = Span { + start: targets + .iter() + .map(|x| x.span.start) + .min() + .expect("targets were empty"), + end: targets + .iter() + .map(|x| x.span.end) + .max() + .expect("targets were empty"), + }; + let path = current_dir(engine_state, stack)?; let (mut target_exists, mut empty_span) = (false, call.head); let mut all_targets: HashMap = HashMap::new(); + for target in targets { if path.to_string_lossy() == target.item || path.as_os_str().to_string_lossy().starts_with(&format!( @@ -275,9 +289,9 @@ fn rm( if all_targets.is_empty() && !force { return Err(ShellError::GenericError( - "No valid paths".into(), - "no valid paths".into(), - Some(empty_span), + "File(s) not found".into(), + "File(s) not found".into(), + Some(targets_span), None, Vec::new(), ));