planarnetwork / transxchange2gtfs

tool to convert transxchange data into a GTFS feed
30 stars 17 forks source link

[Fix] Processing failure when certain [0] index fields not present #37

Closed ChronSyn closed 3 years ago

ChronSyn commented 3 years ago

Description

While attempting to process 19 April 2021 timetable data from https://data.bus-data.dft.gov.uk/timetable/download/bulk_archive, the library failed to process several fields, but I was unable to identify the file which was causing the failure when processing the entire archive as the error thrown was a typical uncaught error in a promise.

The cause of the error was caused by attempting to access certain indices that weren't present present - e.g. Line 128 in TransXChangeStream.ts trying to access stop.TimingStatus[0], but that field or index not being present - essentially, either timingStatus or timingStatus[0] was not present.

Solution implemented

I have added optional chaining and nullish coalescing to several areas. Where appropriate, these fields will return an empty string in place so that the generated output is still valid. I have also updated some checks which were trying to return index 0 to first check if that index is actually available.

There may be other areas where this solution should be extended, but with the changes made here, I was able to successfully process the archive mentioned above.

linusnorton commented 3 years ago

Hey, thanks for sending in a PR. Is it possible to get it without the formatting changes? There's a lot of noise in the PR that makes it hard to review. If it's a bit hard to unpick I can try to apply the changes you made to a new branch

ChronSyn commented 3 years ago

Hey, thanks for sending in a PR. Is it possible to get it without the formatting changes? There's a lot of noise in the PR that makes it hard to review. If it's a bit hard to unpick I can try to apply the changes you made to a new branch

Sorry about that - I hadn't noticed the formatting had been pushed as well. Updated.

linusnorton commented 3 years ago

@ChronSyn this has been released as version 1.8.2 - thanks for the PR.