Skip to content

Commit 22bd036

Browse files
xtqqczzecakebaker
authored andcommitted
refactor(du): simplify error handling
1 parent 2f49d8e commit 22bd036

1 file changed

Lines changed: 4 additions & 6 deletions

File tree

src/uu/du/src/du.rs

Lines changed: 4 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@
66
// spell-checker:ignore fstatat openat dirfd
77

88
use clap::{Arg, ArgAction, ArgMatches, Command, builder::PossibleValue};
9-
use glob::Pattern;
9+
use glob::{Pattern, PatternError};
1010
use rustc_hash::FxHashSet as HashSet;
1111
use std::env;
1212
use std::ffi::{OsStr, OsString};
@@ -749,7 +749,7 @@ enum DuError {
749749
InvalidTimeStyleArg(String),
750750

751751
#[error("{}", translate!("du-error-invalid-glob", "error" => _0))]
752-
InvalidGlob(String),
752+
InvalidGlob(PatternError),
753753
}
754754

755755
impl UError for DuError {}
@@ -785,10 +785,8 @@ fn build_exclude_patterns(matches: &ArgMatches) -> UResult<Vec<Pattern>> {
785785
translate!("du-verbose-adding-to-exclude-list", "pattern" => f.clone())
786786
);
787787
}
788-
match parse_glob::from_str(&f) {
789-
Ok(glob) => exclude_patterns.push(glob),
790-
Err(err) => return Err(DuError::InvalidGlob(err.to_string()).into()),
791-
}
788+
let glob = parse_glob::from_str(&f).map_err(DuError::InvalidGlob)?;
789+
exclude_patterns.push(glob);
792790
}
793791
Ok(exclude_patterns)
794792
}

0 commit comments

Comments
 (0)