From cac42301f8ae64b75f4c5bf7298c8a19c9ef406f Mon Sep 17 00:00:00 2001 From: Rob Bradford Date: Fri, 10 Jun 2022 15:39:04 +0100 Subject: [PATCH] performance-metrics: Produce some error messages if git commands fail It is reasonable for these to fail as it the tool could be run outside of a git repository but by not giving any error message we cannot see issues when we expect the report to have the git details. Signed-off-by: Rob Bradford --- performance-metrics/src/main.rs | 36 ++++++++++++++++++++++++--------- 1 file changed, 27 insertions(+), 9 deletions(-) diff --git a/performance-metrics/src/main.rs b/performance-metrics/src/main.rs index 0065e1534..67969794f 100644 --- a/performance-metrics/src/main.rs +++ b/performance-metrics/src/main.rs @@ -53,18 +53,30 @@ impl Default for MetricsReport { let mut git_human_readable = "".to_string(); if let Ok(git_out) = Command::new("git").args(&["describe", "--dirty"]).output() { if git_out.status.success() { - if let Ok(git_out_str) = String::from_utf8(git_out.stdout) { - git_human_readable = git_out_str.trim().to_string(); - } + git_human_readable = String::from_utf8(git_out.stdout) + .unwrap() + .trim() + .to_string(); + } else { + eprintln!( + "Error generating human readable git reference: {}", + String::from_utf8(git_out.stderr).unwrap() + ); } } let mut git_revision = "".to_string(); if let Ok(git_out) = Command::new("git").args(&["rev-parse", "HEAD"]).output() { if git_out.status.success() { - if let Ok(git_out_str) = String::from_utf8(git_out.stdout) { - git_revision = git_out_str.trim().to_string(); - } + git_revision = String::from_utf8(git_out.stdout) + .unwrap() + .trim() + .to_string(); + } else { + eprintln!( + "Error generating git reference: {}", + String::from_utf8(git_out.stderr).unwrap() + ); } } @@ -74,9 +86,15 @@ impl Default for MetricsReport { .output() { if git_out.status.success() { - if let Ok(git_out_str) = String::from_utf8(git_out.stdout) { - git_commit_date = git_out_str.trim().to_string(); - } + git_commit_date = String::from_utf8(git_out.stdout) + .unwrap() + .trim() + .to_string(); + } else { + eprintln!( + "Error generating git commit date: {}", + String::from_utf8(git_out.stderr).unwrap() + ); } }