split: use map_err instead of match (#12664)

This commit is contained in:
Daniel Hofstetter
2026-06-06 18:56:10 +02:00
committed by GitHub
parent d8157f0e30
commit fab0cbd327
+15 -12
View File
@@ -53,20 +53,23 @@ pub fn uumain(args: impl uucore::Args) -> UResult<()> {
let (args, obs_lines) = handle_obsolete(args);
let matches = uucore::clap_localization::handle_clap_result(uu_app(), args)?;
match Settings::from(&matches, obs_lines.as_deref()) {
Ok(settings) => {
// When using --filter, we write to a child process's stdin which may
// close early. Disable SIGPIPE so we get EPIPE errors instead of
// being terminated, allowing graceful handling of broken pipes.
#[cfg(unix)]
if settings.filter.is_some() {
let _ = uucore::signals::disable_pipe_errors();
}
split(&settings)
let settings = Settings::from(&matches, obs_lines.as_deref()).map_err(|e| {
if e.requires_usage() {
UUsageError::new(1, format!("{e}"))
} else {
USimpleError::new(1, format!("{e}"))
}
Err(e) if e.requires_usage() => Err(UUsageError::new(1, format!("{e}"))),
Err(e) => Err(USimpleError::new(1, format!("{e}"))),
})?;
// When using --filter, we write to a child process's stdin which may
// close early. Disable SIGPIPE so we get EPIPE errors instead of
// being terminated, allowing graceful handling of broken pipes.
#[cfg(unix)]
if settings.filter.is_some() {
let _ = uucore::signals::disable_pipe_errors();
}
split(&settings)
}
/// Extract obsolete shorthand (if any) for specifying lines in following scenarios (and similar)