Skip to content

fix(ResultFormatter): guard heading/airspeed/groundspeed/mach/day/month/departureDay/arrivalDay against NaN (#494) - #521

Open
fuleinist wants to merge 1 commit into
airframesio:masterfrom
fuleinist:fix/494-resultformatter-nan-guards
Open

fix(ResultFormatter): guard heading/airspeed/groundspeed/mach/day/month/departureDay/arrivalDay against NaN (#494)#521
fuleinist wants to merge 1 commit into
airframesio:masterfrom
fuleinist:fix/494-resultformatter-nan-guards

Conversation

@fuleinist

@fuleinist fuleinist commented Aug 11, 2026

Copy link
Copy Markdown
Contributor

Fixes #494.

heading, airspeed, groundspeed, mach, day, month, departureDay, and arrivalDay stored whatever number they received and interpolated it into the formatted string, so Number('---') / Number('***') / non-numeric fields surfaced as literal "NaN", "NaN knots", "NaN mach" items in formatted.items (and NaN in raw).

This adds the same early isNaN guard that altitude, position, flightNumber, temperature, and the timestamp-family formatters already use: NaN input now returns without pushing an item or touching raw, so unknown values simply disappear from the output instead of rendering as "NaN".

Changes:

  • lib/utils/result_formatter.tsif (isNaN(...)) return; guard at the top of the eight affected formatters.
  • lib/utils/result_formatter.test.ts — table test covering NaN input for all eight formatters (no item pushed, raw field left unset), plus valid-value sanity checks for heading, groundspeed, mach, and day.

Out of scope (per the issue): the fuel formatters and the Number('') silent-zero class (#487) are untouched.

Tested: full suite 493 passed / 9 skipped (100 suites), formatter tests 27/27.

Summary by CodeRabbit

  • Bug Fixes

    • Improved handling of unavailable numeric values across result formatting.
    • Prevented invalid entries from appearing in formatted output or raw field values.
    • Preserved expected formatting for valid heading, speed, Mach number, and date values.
  • Tests

    • Added coverage to verify correct behavior for unavailable and valid numeric inputs.

@coderabbitai

coderabbitai Bot commented Aug 11, 2026

Copy link
Copy Markdown

Review Change Stack

Walkthrough

ResultFormatter now ignores NaN inputs for eight numeric methods. Tests verify that invalid values produce no output and valid values retain their existing formatting.

Changes

ResultFormatter NaN handling

Layer / File(s) Summary
NaN guards and regression coverage
lib/utils/result_formatter.ts, lib/utils/result_formatter.test.ts
The groundspeed, airspeed, mach, heading, day, month, departureDay, and arrivalDay methods return before updating raw data or formatted items when they receive NaN. Tests cover skipped NaN values and valid formatted values.

Estimated code review effort: 2 (Simple) | ~10 minutes

Poem

A rabbit checks each number twice,
NaN finds no place among the mice.
Valid headings hop in line,
Knots and days format just fine.
Raw fields stay clean and bright.

🚥 Pre-merge checks | ✅ 5
✅ Passed checks (5 passed)
Check name Status Explanation
Description Check ✅ Passed Check skipped - CodeRabbit’s high-level summary is enabled.
Title check ✅ Passed The title clearly identifies the ResultFormatter methods and the NaN guard fix addressed by the pull request.
Linked Issues check ✅ Passed The changes add NaN guards and tests for all eight formatters required by issue #494.
Out of Scope Changes check ✅ Passed The code and tests remain limited to the NaN handling requirements in issue #494.
Docstring Coverage ✅ Passed No functions found in the changed files to evaluate docstring coverage. Skipping docstring coverage check.
✨ Finishing Touches
🧪 Generate unit tests (beta)
  • Create PR with unit tests

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.

❤️ Share

Comment @coderabbitai help to get the list of available commands.

@coderabbitai coderabbitai Bot left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Actionable comments posted: 1

🤖 Prompt for all review comments with AI agents
Verify each finding against current code. Fix only still-valid issues, skip the
rest with a brief reason, keep changes minimal, and validate.

Inline comments:
In `@lib/utils/result_formatter.test.ts`:
- Line 105: Format the `groundspeed` and `departureDay` entries in the result
formatter test using Prettier’s multiline tuple layout, keeping each tuple’s
existing callback and label unchanged.
🪄 Autofix

Fix all unresolved CodeRabbit comments on this PR:

  • Push a commit to this branch (recommended)
  • Create a new PR with the fixes

ℹ️ Review info
⚙️ Run configuration

Configuration used: Repository UI

Review profile: CHILL

Plan: Pro Plus

Run ID: eda52a60-7147-4c36-9e72-4ca4d127c97d

📥 Commits

Reviewing files that changed from the base of the PR and between 90ad3b2 and e91082a.

📒 Files selected for processing (2)
  • lib/utils/result_formatter.test.ts
  • lib/utils/result_formatter.ts

// than surfacing as literal "NaN" strings (issue #494).
const cases: Array<[string, (dr: DecodeResult) => void, string]> = [
['heading', (dr) => ResultFormatter.heading(dr, NaN), 'heading'],
['groundspeed', (dr) => ResultFormatter.groundspeed(dr, NaN), 'groundspeed'],

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

📐 Maintainability & Code Quality | 🟡 Minor | ⚡ Quick win

Fix the Prettier errors on Line 105 and Line 110.

ESLint reports formatting errors for the groundspeed and departureDay entries. Apply the multiline tuple layout before merging.

Proposed formatting fix
-    ['groundspeed', (dr) => ResultFormatter.groundspeed(dr, NaN), 'groundspeed'],
+    [
+      'groundspeed',
+      (dr) => ResultFormatter.groundspeed(dr, NaN),
+      'groundspeed',
+    ],
-    ['departureDay', (dr) => ResultFormatter.departureDay(dr, NaN), 'departure_day'],
+    [
+      'departureDay',
+      (dr) => ResultFormatter.departureDay(dr, NaN),
+      'departure_day',
+    ],

Also applies to: 110-110

🧰 Tools
🪛 ESLint

[error] 105-105: Replace 'groundspeed',·(dr)·=>·ResultFormatter.groundspeed(dr,·NaN),·'groundspeed' with ⏎······'groundspeed',⏎······(dr)·=>·ResultFormatter.groundspeed(dr,·NaN),⏎······'groundspeed',⏎····

(prettier/prettier)

🤖 Prompt for AI Agents
Verify each finding against current code. Fix only still-valid issues, skip the
rest with a brief reason, keep changes minimal, and validate.

In `@lib/utils/result_formatter.test.ts` at line 105, Format the `groundspeed` and
`departureDay` entries in the result formatter test using Prettier’s multiline
tuple layout, keeping each tuple’s existing callback and label unchanged.

Source: Linters/SAST tools

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

1 participant