From 02c4c8bb02f57aa5b8f0253fb5c9f3e9a2f3feb4 Mon Sep 17 00:00:00 2001 From: Jake Shadle Date: Wed, 24 Apr 2024 13:54:37 +0200 Subject: [PATCH] Fix stats summary/exit code when logging is disabled (#657) Disabling logging would cause both the stats at the end, but more crucially, the exit code (if errors occurred), to be incorrect. Resolves: #652 --- src/cargo-deny/check.rs | 44 ++++++++++++++++++++--------------------- 1 file changed, 21 insertions(+), 23 deletions(-) diff --git a/src/cargo-deny/check.rs b/src/cargo-deny/check.rs index 68e7898d..0ae335fc 100644 --- a/src/cargo-deny/check.rs +++ b/src/cargo-deny/check.rs @@ -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); + } } }