From 25b29902c08b2944bd0038f5fb472e21e30f0c97 Mon Sep 17 00:00:00 2001 From: Markus Pettersson Date: Wed, 11 Oct 2023 10:20:14 +0200 Subject: [PATCH] Fix do not fail when summarizing logs --- test/test-manager/src/main.rs | 2 +- test/test-manager/src/summary.rs | 22 ++++++++++++++-------- 2 files changed, 15 insertions(+), 9 deletions(-) diff --git a/test/test-manager/src/main.rs b/test/test-manager/src/main.rs index 0852916791fa..e341759b1335 100644 --- a/test/test-manager/src/main.rs +++ b/test/test-manager/src/main.rs @@ -284,7 +284,7 @@ async fn main() -> Result<()> { result } Commands::FormatTestReports { reports } => { - summary::print_summary_table(&reports).await?; + summary::print_summary_table(&reports).await; Ok(()) } Commands::Update { name } => { diff --git a/test/test-manager/src/summary.rs b/test/test-manager/src/summary.rs index 63871678723b..cad11aca83cb 100644 --- a/test/test-manager/src/summary.rs +++ b/test/test-manager/src/summary.rs @@ -121,12 +121,12 @@ pub struct Summary { impl Summary { /// Read test summary from `path`. - pub async fn parse_log(path: &Path) -> Result { + pub async fn parse_log>(path: P) -> Result { let file = fs::OpenOptions::new() .read(true) - .open(path) + .open(&path) .await - .map_err(|err| Error::Open(err, path.to_path_buf()))?; + .map_err(|err| Error::Open(err, path.as_ref().to_path_buf()))?; let mut lines = tokio::io::BufReader::new(file).lines(); @@ -160,10 +160,18 @@ impl Summary { } /// Outputs an HTML table, to stdout, containing the results of the given log files. -pub async fn print_summary_table>(summary_files: &[P]) -> Result<(), Error> { - let mut summaries = vec![]; +/// +/// This is a best effort attempt at summarizing the log files which do +/// exist. If some log file which is expected to exist, but for any reason fails to +/// be parsed, we should not abort the entire summarization. +pub async fn print_summary_table>(summary_files: &[P]) { + let mut summaries = Vec::new(); + let mut failed_to_parse = Vec::new(); for sumfile in summary_files { - summaries.push(Summary::parse_log(sumfile.as_ref()).await?); + match Summary::parse_log(sumfile).await { + Ok(summary) => summaries.push(summary), + Err(_) => failed_to_parse.push(sumfile), + } } // Collect test details @@ -274,6 +282,4 @@ pub async fn print_summary_table>(summary_files: &[P]) -> Result< // Print explanation of test result println!("

{} = Test passed

", TestResult::PASS_STR); println!("

{} = Test failed

", TestResult::FAIL_STR); - - Ok(()) }