Skip to content

Commit 004e064

Browse files
committed
Handle invalid durations more gracefully
1 parent f7a329c commit 004e064

1 file changed

Lines changed: 8 additions & 4 deletions

File tree

src/frontend.rs

Lines changed: 8 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -339,10 +339,14 @@ pub struct ModuleReviewMetrics {
339339
impl ReviewMetricsTemplate {
340340
pub fn format_duration(&self, duration: &Option<TimeDelta>) -> String {
341341
if let Some(duration) = duration {
342-
let secs = duration.to_std().unwrap().as_secs();
343-
let secs_without_hours = secs - (secs % (60 * 60));
344-
humantime::format_duration(std::time::Duration::from_secs(secs_without_hours))
345-
.to_string()
342+
if let Ok(duration) = duration.to_std() {
343+
let secs = duration.as_secs();
344+
let secs_without_hours = secs - (secs % (60 * 60));
345+
humantime::format_duration(std::time::Duration::from_secs(secs_without_hours))
346+
.to_string()
347+
} else {
348+
format!("Invalid duration: {:?}", duration)
349+
}
346350
} else {
347351
"Not yet".to_owned()
348352
}

0 commit comments

Comments
 (0)