Skip to content

Commit 7747c63

Browse files
committed
graph: Make attempts to create invalid BlockTime easier to diagnose
We can't really pass a Result back since this is called in a lot of places where Results aren't accepted. We make at least sure that the panic from trying to create an invalid BlockTime is easier to diagnose from logs.
1 parent 3898646 commit 7747c63

1 file changed

Lines changed: 5 additions & 1 deletion

File tree

graph/src/blockchain/types.rs

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -341,7 +341,11 @@ impl BlockTime {
341341
/// Construct a block time that is the given number of seconds and
342342
/// nanoseconds after the Unix epoch
343343
pub fn since_epoch(secs: i64, nanos: u32) -> Self {
344-
Self(DateTime::from_timestamp(secs, nanos).unwrap())
344+
Self(
345+
DateTime::from_timestamp(secs, nanos)
346+
.ok_or_else(|| anyhow!("invalid block time: {}s {}ns", secs, nanos))
347+
.unwrap(),
348+
)
345349
}
346350

347351
/// Construct a block time for tests where blocks are exactly 10s apart

0 commit comments

Comments
 (0)