safeDuration returns a-b. If a or b is nil, it returns 0. This is because we often dereference a time pointer, which can cause a panic. These dereferences are used to calculate durations, which are not critical, and therefor should not break things when it fails. A panic has been observed in a test.
(sw *stageWriter, a, b *time.Time)
| 381 | // when it fails. |
| 382 | // A panic has been observed in a test. |
| 383 | func safeDuration(sw *stageWriter, a, b *time.Time) time.Duration { |
| 384 | if a == nil || b == nil { |
| 385 | if sw != nil { |
| 386 | // Ideally the message includes which fields are <nil>, but you can |
| 387 | // use the surrounding log lines to figure that out. And passing more |
| 388 | // params makes this unwieldy. |
| 389 | sw.Log(time.Now(), codersdk.LogLevelWarn, "Warning: Failed to calculate duration from a time being <nil>.") |
| 390 | } |
| 391 | return 0 |
| 392 | } |
| 393 | return a.Sub(*b) |
| 394 | } |
| 395 | |
| 396 | // GetProgressiveInterval returns an interval that increases over time. |
| 397 | // The interval starts at baseInterval and increases to |
no test coverage detected