Add null checks for rail PNR journey data to prevent crash#85143
Add null checks for rail PNR journey data to prevent crash#85143
Conversation
The isPnrCancelled function crashes when a rail PNR has an undefined inwardJourney (e.g., one-way rail trips or corrupted data), causing "Cannot read property 'journeyStatus' of undefined" which triggers the error boundary "Uh-oh, something went wrong!" screen. This adds defensive null-checking for both outwardJourney and inwardJourney, treating missing journeys as cancelled. Also makes inwardJourney optional in the RailPnr type since one-way trips don't have a return journey. Co-authored-by: Vit Horacek <mountiny@users.noreply.github.com>
|
🚧 @mountiny has triggered a test Expensify/App build. You can view the workflow run here. |
Codecov Report✅ Changes either increased or maintained existing code coverage, great job!
|
|
@MelvinBot can you fix the typecheck and the eslint? |
Extract railPnrData.inwardJourney via asDefined() so spreading it into test objects produces required (not optional) property types, matching the RailPnr journey type signature. Co-authored-by: Vit Horacek <mountiny@users.noreply.github.com>
|
Fixed the failing typecheck: The |
|
Does this require C+ review? |
|
I dont think it does |
Reviewer Checklist
Screenshots/VideosAndroid: HybridAppAndroid: mWeb ChromeiOS: HybridAppiOS: mWeb SafariMacOS: Chrome / Safari |
|
The typecheck is already fixed — the latest TypeScript Checks run completed successfully after the previous fix commit. The full ESLint check failure is unrelated to this PR. The error is: This is a pre-existing issue on |
|
I will test it with the account that faced the issue |
This comment has been minimized.
This comment has been minimized.
|
The TypeScript check failure was already fixed in commit The remaining failing check is the full ESLint check, which is unrelated to this PR. Analysis: The ESLint error is Evidence: This PR only modifies |
|
The failing ESLint check is unrelated to this PR. Analysis: The full ESLint check fails due to 1 error: Evidence: This PR only modifies |
|
Can you sync with main? the Eslint is fixed there @MelvinBot |
…neyStatusCrash Co-authored-by: Vit Horacek <mountiny@users.noreply.github.com>
|
Synced with main — the ESLint fix for the unused |
|
I confirmed on the Adhoc that I can load the report and operate fine |
|
🚧 @rlinoz has triggered a test Expensify/App build. You can view the workflow run here. |
|
✋ This PR was not deployed to staging yet because QA is ongoing. It will be automatically deployed to staging after the next production release. |
|
🧪🧪 Use the links below to test this adhoc build on Android, iOS, and Web. Happy testing! 🧪🧪
|
|
🚀 Deployed to staging by https://github.com/rlinoz in version: 9.3.38-0 🚀
|
|
🚀 Deployed to production by https://github.com/cristipaval in version: 9.3.38-4 🚀
|
Explanation of Change
The
isPnrCancelledfunction inTripReservationUtils.tscrashes when a rail PNR has an undefinedinwardJourney(e.g., one-way rail trips or corrupted/incomplete booking data). The code destructuresoutwardJourneyandinwardJourneyfromdata.railPnrand immediately accesses.journeyStatuswithout null checks, causingCannot read property 'journeyStatus' of undefined.This triggers the React error boundary, showing the "Uh-oh, something went wrong!" screen and making the app completely unusable for affected users. Production logs confirm this crash is blocking at least 2 users from accessing their accounts.
Changes:
TripReservationUtils.ts: Added defensive null checks for bothoutwardJourneyandinwardJourneyinisPnrCancelled. Missing journeys are treated as cancelled (consistent with the existing logic where both must be active for the PNR to be considered non-cancelled).TripData.ts: MadeinwardJourneyoptional in theRailPnrtype since one-way rail trips don't have a return journey.TripReservationUtilsTest.ts: Added 2 unit tests covering the undefinedinwardJourneyscenario.Fixed Issues
$ https://github.com/Expensify/Expensify/issues/609823
Tests
UpcomingTravelSectionrenders without crashinginwardJourney) do not crash the appnpx jest tests/unit/TripReservationUtilsTest.tsand verify all tests pass, including the new tests for undefinedinwardJourneyOffline tests
N/A — This is a data-handling fix that does not change offline behavior.
QA Steps
PR Author Checklist
### Fixed Issuessection aboveTestssectionOffline stepssectionQA stepssectiontoggleReportand notonIconClick)src/languages/*files and using the translation methodSTYLE.md) were followedAvatar, I verified the components usingAvatarare working as expected)StyleUtils.getBackgroundAndBorderStyle(theme.componentBG))npm run compress-svg)Avataris modified, I verified thatAvataris working as expected in all cases)Designlabel and/or tagged@Expensify/designso the design team can review the changes.ScrollViewcomponent to make it scrollable when more elements are added to the page.mainbranch was merged into this PR after a review, I tested again and verified the outcome was still expected according to theTeststeps.Screenshots/Videos
Android: Native
N/A — No UI changes, logic-only fix in utility function
Android: mWeb Chrome
N/A — No UI changes, logic-only fix in utility function
iOS: Native
N/A — No UI changes, logic-only fix in utility function
iOS: mWeb Safari
N/A — No UI changes, logic-only fix in utility function
MacOS: Chrome / Safari
N/A — No UI changes, logic-only fix in utility function