Better error message when rm can't find files (#7098)

This commit is contained in:
Reilly Wood 2022-11-10 23:05:09 -08:00 committed by GitHub
parent 13515c5eb0
commit cb926f7b49
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23

View File

@ -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<PathBuf, Span> = 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(),
));