fix: guard timestamp formatting against NaN input (#498) - #513
Conversation
timestampToString(NaN) fell through to new Date(NaN).toISOString() and threw RangeError, aborting the entire MessageDecoder.decode() for any plugin feeding a malformed time field into the timestamp-family formatters (e.g. Label_44_ETA with a non-numeric timestamp field). Guard at two levels: timestampToString returns '' for NaN, and ResultFormatter.timestamp/eta/out/off/on/in/engineStart/engineStop skip the field entirely when the input is NaN, mirroring the existing isNaN guards on position/altitude/flightNumber. Note: out was not listed in airframesio#498 but shares the exact pattern, so it is guarded too. Tests: timestampToString NaN regression, per-method NaN guard table test, Label_44_ETA end-to-end repro from airframesio#498. Full suite 480 passed / 9 skipped (pre-existing).
|
Warning Review limit reached
Next review available in: 53 minutes You've used all free OSS reviews for now. Wait for the free limit to reset to keep reviewing this public repository. How can I continue?After more reviews become available, a review can be triggered using the To avoid repeated limits, reduce automatic review volume by pausing incremental auto-reviews earlier, using label-based review opt-in, excluding WIP or generated PR titles, or requesting reviews manually when the PR is ready. If your team needs uninterrupted high-volume reviews, an organization admin can enable usage-based reviews. How do review limits work?CodeRabbit enforces per-developer PR review limits for each organization. Most developers receive the normal plan review availability. For paid Pro and Pro+ PR reviews, CodeRabbit uses adaptive limits for sustained high-volume activity. When a developer's recent PR review activity reaches the 95th percentile or higher among CodeRabbit users, additional reviews become available more gradually as earlier reviews age out of the rolling window. Please refer docs for additional details. Review details⚙️ Run configurationConfiguration used: Repository UI Review profile: CHILL Plan: Pro Plus Run ID: 📒 Files selected for processing (5)
Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out. Comment |
There was a problem hiding this comment.
🟢 Ready to approve
The changes directly address the reported crash path with targeted guards and include focused unit and end-to-end regression tests.
This review doesn't count toward merge requirements. Sign up for the private preview to control whether Copilot approvals count.
Pull request overview
This PR fixes a crash where malformed/non-numeric time fields could propagate NaN into DateTimeUtils.timestampToString(), triggering new Date(NaN).toISOString() → RangeError: Invalid time value and aborting MessageDecoder.decode().
Changes:
- Add a
NaNguard inDateTimeUtils.timestampToString()to return''instead of throwing. - Add early-return
NaNguards across the “timestamp-family”ResultFormattermethods to avoid setting raw fields or emitting formatted items when the input isNaN. - Add unit + end-to-end tests covering the regression (including the Label 44 ETA repro path from issue #498).
File summaries
| File | Description |
|---|---|
| lib/utils/result_formatter.ts | Skips timestamp-related formatting entirely when the provided time value is NaN. |
| lib/utils/result_formatter.test.ts | Adds table-driven tests ensuring timestamp-family formatters don’t throw and don’t emit output on NaN. |
| lib/plugins/Label_44_ETA.test.ts | Adds an end-to-end repro ensuring a malformed timestamp field does not abort decoding. |
| lib/DateTimeUtils.ts | Prevents timestampToString(NaN) from throwing by returning an empty string. |
| lib/DateTimeUtils.test.ts | Adds tests verifying timestampToString(NaN) is non-throwing and valid TOD formatting still works. |
Review details
- Files reviewed: 5/5 changed files
- Comments generated: 0
- Review effort level: Lite
We're testing this review assessment. Please use 👍 or 👎 to tell us if it's correct.
Fixes #498.
Summary
DateTimeUtils.timestampToString(NaN)fell through both range checks (NaN < 86400is false) tonew Date(NaN).toISOString(), throwingRangeError: Invalid time value. SinceMessageDecoder.decode()has no top-level try/catch, one malformed time field aborted the entire decode.Repro from the issue: a Label 44 ETA message with a non-numeric timestamp field (e.g.
...1107,ABCD,0208,...) →convertHHMMSSToTod('ABCD')→NaN→ResultFormatter.timestamp(result, NaN)→ RangeError.Fix
Two levels, mirroring the existing
isNaNguards onposition/altitude/flightNumber:DateTimeUtils.timestampToStringreturns''for NaN instead of throwing.timestamp,eta,out,off,on,in,engineStart,engineStop— return early without setting the raw field or pushing a formatted item when the input is NaN.Note:
outwas not listed in #498 but has the identical pattern, so it is guarded too.Tests
DateTimeUtils.test.ts: timestampToString(NaN) returns '' without throwing; valid tod still formats.result_formatter.test.ts: table test covering all 8 timestamp-family methods with NaN — no throw, no item, no raw field.Label_44_ETA.test.ts: end-to-end repro from Bug: DateTimeUtils.timestampToString(NaN) throws RangeError, aborting MessageDecoder.decode() for any non-numeric time field #498 — decode completes withdecodeLevel: 'full', timestamp item skipped, ETA and other fields intact.Full suite: 480 passed, 9 skipped (pre-existing). The
flight_plan_utilstsc errors visible undertsc --noEmitare pre-existing on master and untouched by this change.