-
Notifications
You must be signed in to change notification settings - Fork 2
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Gracefully handle no departures for Line Map #2047
Conversation
departures | ||
|> Stream.reject(fn %Departure{prediction: p} -> is_nil(p) end) | ||
|> Stream.reject(fn %Departure{prediction: %Prediction{trip: t}} -> is_nil(t) end) | ||
|> Stream.filter(fn %Departure{prediction: %Prediction{trip: %Trip{direction_id: d}}} -> | ||
d == direction_id | ||
end) | ||
|> Enum.count() | ||
Enum.count( | ||
departures, | ||
&match?(%Departure{prediction: %Prediction{trip: %Trip{direction_id: ^direction_id}}}, &1) | ||
) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
note: As called out in the PR description this isn't really related to this bug. I'm happy to remove this if you'd like.
use with and pattern matching to handle sequence of possible errors
4eca2ff
to
c525734
Compare
Coverage of commit
|
|
c9a9dd9
to
44487c8
Compare
Coverage of commit
|
@digitalcora hmmm there were more |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This looks great. Definitely like the most recent commit over the initial solution. I'm fighting myself on whether the other errors could be in scope just because the screen can still be useful if we don't have this piece. If another error happened, it would be good to log it but should let the screen render what it can. I agree with @digitalcora on the definition of a good crash, but don't think the date functions would error because of anything but a data issue. Would love to hear other thoughts though.
Looking at the trade-off of the added complexity to log an error and continue anyway in this specific case, versus how likely the errors are to occur... I'd say it's questionably worth it. It's not like we do this in any disciplined fashion everywhere we use e.g. |
@digitalcora FWIW, based on the typespecs of the Exampleiex(3)> departure = %Screens.V2.Departure{prediction: %Screens.Predictions.Prediction{}, schedule: %Screens.Schedules.Schedule{}}
%Screens.V2.Departure{
prediction: %Screens.Predictions.Prediction{
id: nil,
trip: nil,
stop: nil,
route: nil,
vehicle: nil,
alerts: [],
arrival_time: nil,
departure_time: nil,
stop_headsign: nil,
track_number: nil
},
schedule: %Screens.Schedules.Schedule{
id: nil,
trip: nil,
stop: nil,
route: nil,
trip_id: nil,
arrival_time: nil,
departure_time: nil,
stop_headsign: nil,
track_number: nil,
direction_id: nil
}
}
iex(4)> Screens.V2.Departure.time(departure)
nil However, I feel like the juice probably isn't worth the squeeze if we aren't seeing issues like this more frequently. |
Asana task: [Screens 🐞] Gracefully handle no departures for Line Map
Description
Handles the case when there fewer than two departures with predictions but also no departures without a prediction.
nil
toScreens.V2.Departure.time/1
which raised an exceptionOther changes
Enum.count/2
Known issues / thoughts
This doesn't eliminate all possible errors related to the
nil
ability of departures and the arrival and departure fields within schedules and predictions but is instead focused on the specific error reported to Sentry. A refactor to account for that class of errors would have a much larger surface area. Happy to address this if needed!