Skip to content

Commit

Permalink
Fix stats summary/exit code when logging is disabled (#657)
Browse files Browse the repository at this point in the history
Disabling logging would cause both the stats at the end, but more
crucially, the exit code (if errors occurred), to be incorrect.

Resolves: #652
  • Loading branch information
Jake-Shadle committed Apr 24, 2024
1 parent d50a347 commit 02c4c8b
Showing 1 changed file with 21 additions and 23 deletions.
44 changes: 21 additions & 23 deletions src/cargo-deny/check.rs
Original file line number Diff line number Diff line change
Expand Up @@ -540,30 +540,28 @@ fn print_diagnostics(
) {
use cargo_deny::diag::Check;

match crate::common::DiagPrinter::new(log_ctx, krates, feature_depth) {
Some(printer) => {
for pack in rx {
let check_stats = match pack.check {
Check::Advisories => stats.advisories.as_mut().unwrap(),
Check::Bans => stats.bans.as_mut().unwrap(),
Check::Licenses => stats.licenses.as_mut().unwrap(),
Check::Sources => stats.sources.as_mut().unwrap(),
};

for diag in pack.iter() {
match diag.diag.severity {
Severity::Error => check_stats.errors += 1,
Severity::Warning => check_stats.warnings += 1,
Severity::Note => check_stats.notes += 1,
Severity::Help => check_stats.helps += 1,
Severity::Bug => {}
}
}

let mut lock = printer.lock();
lock.print_krate_pack(pack, &files);
let dp = crate::common::DiagPrinter::new(log_ctx, krates, feature_depth);

for pack in rx {
let check_stats = match pack.check {
Check::Advisories => stats.advisories.as_mut().unwrap(),
Check::Bans => stats.bans.as_mut().unwrap(),
Check::Licenses => stats.licenses.as_mut().unwrap(),
Check::Sources => stats.sources.as_mut().unwrap(),
};

for diag in pack.iter() {
match diag.diag.severity {
Severity::Error => check_stats.errors += 1,
Severity::Warning => check_stats.warnings += 1,
Severity::Note => check_stats.notes += 1,
Severity::Help => check_stats.helps += 1,
Severity::Bug => {}
}
}
None => while rx.recv().is_ok() {},

if let Some(mut lock) = dp.as_ref().map(|dp| dp.lock()) {
lock.print_krate_pack(pack, &files);
}
}
}

0 comments on commit 02c4c8b

Please sign in to comment.