Skip to content

Commit 6ca0ece

Browse files
committed
fix: handle missing sequence lookups with -1 sentinel value
1 parent 3f4dc8a commit 6ca0ece

2 files changed

Lines changed: 5 additions & 5 deletions

File tree

internal/restapi/arrival_and_departure_for_stop_handler.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -832,7 +832,7 @@ func (api *RestAPI) getNumberOfStopsAway(ctx context.Context, targetTripID strin
832832
_, nextStopCode, err := utils.ExtractAgencyIDAndCodeID(tripStatus.NextStop)
833833
if err == nil {
834834
nextStopSeq := api.getBlockSequenceForStopID(ctx, activeTripID, nextStopCode, serviceDate)
835-
if nextStopSeq >= 0 {
835+
if nextStopSeq != -1 && targetGlobalSeq != -1 {
836836
numberOfStopsAway := targetGlobalSeq - nextStopSeq
837837
return &numberOfStopsAway
838838
}

internal/restapi/block_sequence_helper.go

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,7 @@ func (api *RestAPI) getBlockSequenceForStopSequence(ctx context.Context, tripID
1616

1717
blockTrips, err := api.GtfsManager.GtfsDB.Queries.GetTripsByBlockID(ctx, blockID)
1818
if err != nil {
19-
return 0
19+
return rawSequenceToOrdinal(api, ctx, tripID, stopSequence)
2020
}
2121

2222
type TripWithDetails struct {
@@ -69,7 +69,7 @@ func (api *RestAPI) getBlockSequenceForStopSequence(ctx context.Context, tripID
6969
return blockSequence + i
7070
}
7171
}
72-
return blockSequence
72+
return -1
7373
}
7474
blockSequence += len(stopTimes)
7575
}
@@ -82,14 +82,14 @@ func (api *RestAPI) getBlockSequenceForStopSequence(ctx context.Context, tripID
8282
func rawSequenceToOrdinal(api *RestAPI, ctx context.Context, tripID string, stopSequence int) int {
8383
stopTimes, err := api.GtfsManager.GtfsDB.Queries.GetStopTimesForTrip(ctx, tripID)
8484
if err != nil {
85-
return 0
85+
return -1
8686
}
8787
for i, st := range stopTimes {
8888
if int(st.StopSequence) == stopSequence {
8989
return i
9090
}
9191
}
92-
return 0
92+
return -1
9393
}
9494

9595
// getBlockSequenceForStopID returns the global block sequence index for the first

0 commit comments

Comments
 (0)