Skip to content

Commit 7379810

Browse files
Avoid panicking on negative durations
1 parent 365c12f commit 7379810

File tree

1 file changed

+7
-1
lines changed

1 file changed

+7
-1
lines changed

src/server/routes/ui/experiments.rs

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -127,7 +127,13 @@ struct ExperimentContext {
127127
}
128128

129129
fn humanize(duration: Duration) -> String {
130-
let duration = duration.to_std().expect("non-negative duration");
130+
let duration = match duration.to_std() {
131+
Ok(d) => d,
132+
Err(_) => {
133+
// Don't try to make it pretty as a fallback.
134+
return format!("{:?}", duration);
135+
}
136+
};
131137
if duration.as_secs() < 60 {
132138
format!("{duration:?}")
133139
} else if duration.as_secs() < 60 * 60 {

0 commit comments

Comments
 (0)