Skip to content

Commit 82a1969

Browse files
committed
matching: don't throw but return as unmatched if picking StopTimeUpdates failed 🐛
Often `matchingSTUN` is missing because `tripUpdate.stop_time_update[]` is too small. This is perfectly valid (albeit unusable) input for gtfs-rt-feed, so we merely log this as a failed matching instead of an erroneous matching. follow-up of f1d76b3
1 parent 2446f3a commit 82a1969

File tree

1 file changed

+25
-3
lines changed

1 file changed

+25
-3
lines changed

lib/match-with-schedule-trip.js

+25-3
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
import {createHash} from 'node:crypto'
2-
import {deepStrictEqual, ok} from 'node:assert/strict'
2+
import {deepStrictEqual} from 'node:assert/strict'
33
import {DateTime} from 'luxon'
44
import maxBy from 'lodash/maxBy.js'
55
import {
@@ -583,9 +583,31 @@ const createMatchGtfsRtTripUpdateWithScheduleStopTimes = async (cfg, opt = {}) =
583583
snapRange: 5, // todo: make customisable
584584
}, tripUpdate)
585585
const matchingSTU0 = tripUpdate.stop_time_update[iMatchingSTU0]
586-
ok(matchingSTU0, `StopTimeUpdate matchingSTU0 (${iMatchingSTU0}) should exist`)
586+
if(!matchingSTU0) {
587+
logger.warn({
588+
...logCtx,
589+
iMatchingSTU0,
590+
matchingSTU0,
591+
}, `not trying to match because StopTimeUpdate matchingSTU0 (${iMatchingSTU0}) is missing`)
592+
return {
593+
tripUpdate,
594+
isMatched: false,
595+
isCached: false,
596+
}
597+
}
587598
const matchingSTUN = tripUpdate.stop_time_update[iMatchingSTUN]
588-
ok(matchingSTUN, `StopTimeUpdate matchingSTUN (${iMatchingSTUN}) should exist`)
599+
if(!matchingSTUN) {
600+
logger.warn({
601+
...logCtx,
602+
iMatchingSTUN,
603+
matchingSTUN,
604+
}, `not trying to match because StopTimeUpdate matchingSTUN (${iMatchingSTUN}) is missing`)
605+
return {
606+
tripUpdate,
607+
isMatched: false,
608+
isCached: false,
609+
}
610+
}
589611
const stopTimes = [
590612
[
591613
'st' + iMatchingSTU0, // alias

0 commit comments

Comments
 (0)