Skip to content

Commit

Permalink
Error handling
Browse files Browse the repository at this point in the history
  • Loading branch information
konstin committed Aug 25, 2023
1 parent 2608f5b commit 613f043
Showing 1 changed file with 12 additions and 11 deletions.
23 changes: 12 additions & 11 deletions crates/ruff_cli/src/commands/format.rs
Original file line number Diff line number Diff line change
Expand Up @@ -41,7 +41,7 @@ pub(crate) fn format(cli: &Arguments, overrides: &Overrides) -> anyhow::Result<E
bail!("no python files in TODO(@konstin) pass them in")
}

let results: Vec<Result<(), FormatterIterationError>> = paths
let all_success = paths
.into_par_iter()
.map(|dir_entry| {
let dir_entry = dir_entry?;
Expand All @@ -65,16 +65,17 @@ pub(crate) fn format(cli: &Arguments, overrides: &Overrides) -> anyhow::Result<E

format_path(path, options)
})
.collect();

let mut all_success = true;
for result in results {
if let Err(err) = result {
// The inner errors are all flat, i.e. none of them has a source
eprintln!("{}", err.to_string().red().bold());
all_success = false;
}
}
.map(|result| {
match result {
Ok(()) => true,
Err(err) => {
// The inner errors are all flat, i.e. none of them has a source
eprintln!("{}", err.to_string().red().bold());
false
}
}
})
.all(|success| success);

if all_success {
Ok(ExitStatus::Success)
Expand Down

0 comments on commit 613f043

Please sign in to comment.