From fab0cbd327b9d413b8c7a64e16f0a4fdfd8f42cc Mon Sep 17 00:00:00 2001 From: Daniel Hofstetter Date: Sat, 6 Jun 2026 18:56:10 +0200 Subject: [PATCH] split: use map_err instead of match (#12664) --- src/uu/split/src/split.rs | 27 +++++++++++++++------------ 1 file changed, 15 insertions(+), 12 deletions(-) diff --git a/src/uu/split/src/split.rs b/src/uu/split/src/split.rs index b95337d53..368397113 100644 --- a/src/uu/split/src/split.rs +++ b/src/uu/split/src/split.rs @@ -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)