Fix du error message (#7460)

BEFORE:
```
〉du *.***
Error:
  × wildcards are either regular `*` or recursive `**`
   ╭─[entry #6:1:1]
 1 │ du *.***
   · ─┬
   ·  ╰── glob error
   ╰────
```
AFTER:
```
〉du *.***
Error:
  × glob error
   ╭─[entry #8:1:1]
 1 │ du *.***
   ·    ──┬──
   ·      ╰── wildcards are either regular `*` or recursive `**`
   ╰────

```
This commit is contained in:
Leon 2022-12-13 22:11:55 +10:00 committed by GitHub
parent d83dbc3670
commit e2c1216c1b
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23

View File

@ -97,8 +97,8 @@ impl Command for Du {
let exclude = args.exclude.map_or(Ok(None), move |x| { let exclude = args.exclude.map_or(Ok(None), move |x| {
Pattern::new(&x.item).map(Some).map_err(|e| { Pattern::new(&x.item).map(Some).map_err(|e| {
ShellError::GenericError( ShellError::GenericError(
e.msg.to_string(),
"glob error".to_string(), "glob error".to_string(),
e.msg.to_string(),
Some(x.span), Some(x.span),
None, None,
Vec::new(), Vec::new(),
@ -109,20 +109,25 @@ impl Command for Du {
let include_files = args.all; let include_files = args.all;
let mut paths = match args.path { let mut paths = match args.path {
Some(p) => { Some(p) => {
let p = p.item.to_str().expect("Why isn't this encoded properly?"); let item = p.item.to_str().expect("Why isn't this encoded properly?");
nu_glob::glob_with(p, GLOB_PARAMS) match nu_glob::glob_with(item, GLOB_PARAMS) {
} // Convert the PatternError to a ShellError, preserving the span
None => nu_glob::glob_with("*", GLOB_PARAMS), // of the inputted glob.
} Err(e) => {
.map_err(|e| { return Err(ShellError::GenericError(
ShellError::GenericError(
e.msg.to_string(),
"glob error".to_string(), "glob error".to_string(),
Some(tag), e.msg.to_string(),
Some(p.span),
None, None,
Vec::new(), Vec::new(),
) ))
})? }
Ok(path) => path,
}
}
// The * pattern should never fail.
None => nu_glob::glob_with("*", GLOB_PARAMS).expect("du: * pattern failed to glob"),
}
.filter(move |p| { .filter(move |p| {
if include_files { if include_files {
true true