Collect result in format CLI (#6924)

This commit is contained in:
Charlie Marsh 2023-08-27 16:02:18 -04:00 committed by GitHub
parent 292fdd978e
commit a871714705
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23

View file

@ -32,7 +32,7 @@ pub(crate) fn format(cli: &Arguments, overrides: &Overrides) -> Result<ExitStatu
return Ok(ExitStatus::Success); return Ok(ExitStatus::Success);
} }
let all_success = paths let result = paths
.into_par_iter() .into_par_iter()
.map(|dir_entry| { .map(|dir_entry| {
let dir_entry = dir_entry?; let dir_entry = dir_entry?;
@ -57,21 +57,18 @@ pub(crate) fn format(cli: &Arguments, overrides: &Overrides) -> Result<ExitStatu
format_path(path, options) format_path(path, options)
}) })
.map(|result| { .map(|result| {
match result { if let Err(err) = result.as_ref() {
Ok(()) => true,
Err(err) => {
// The inner errors are all flat, i.e., none of them has a source. // The inner errors are all flat, i.e., none of them has a source.
#[allow(clippy::print_stderr)] #[allow(clippy::print_stderr)]
{ {
eprintln!("{}", err.to_string().red().bold()); eprintln!("{}", err.to_string().red().bold());
} }
false
}
} }
result
}) })
.all(|success| success); .collect::<Result<Vec<_>, _>>();
if all_success { if result.is_ok() {
Ok(ExitStatus::Success) Ok(ExitStatus::Success)
} else { } else {
Ok(ExitStatus::Error) Ok(ExitStatus::Error)