Skip to content

fix(UpcomingDepartures): Don't return nil departure_seconds when prediction has nil times#3010

Open
joshlarson wants to merge 1 commit intomainfrom
jdl/sf2.0/fix-arithmetic-error-in-prediction-time-display
Open

fix(UpcomingDepartures): Don't return nil departure_seconds when prediction has nil times#3010
joshlarson wants to merge 1 commit intomainfrom
jdl/sf2.0/fix-arithmetic-error-in-prediction-time-display

Conversation

@joshlarson
Copy link
Contributor

Scope

Asana Ticket: ArithmeticError: bad argument in arithmetic expression

In the rare cases when a prediction sets arrival and departure time to nil, but doesn't have a schedule_relationship of :skipped or :cancelled, then UpcomingDepartures.upcoming_departures/1 will return an upcoming departure with an arrival status of {:departure_seconds, nil}, which then causes an ArithmeticError when ScheduleFinderLive tries to render it.

Implementation

  • Handle the case when a prediction sets arrival time and departure time to nil.
  • I made the assumption that we'd want to render those the same way we render "Scheduled" departures, and that we'd want to drop them for subway.

How to test

This is an unusual situation, one that I've never seen in the wild. I was only able to validate this by running the test cases added in this PR.

@joshlarson joshlarson requested a review from a team as a code owner March 12, 2026 16:21
@joshlarson joshlarson requested a review from jlucytan March 12, 2026 16:21
Copy link
Contributor

@lvachon1 lvachon1 left a comment

Choose a reason for hiding this comment

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

Looks good from here

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

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants