OpenHistoricalMap / issues

File your issues here, regardless of repo until we get all our repos squared away; we don't want to miss anything.
Creative Commons Zero v1.0 Universal
19 stars 1 forks source link

Error labeling element with invalid end date — RangeError: date value is not finite in DateTimeFormat.formatRangeToParts() #826

Closed 1ec5 closed 5 months ago

1ec5 commented 5 months ago

When a relation has an invalid end date, it isn’t possible to save edits to its members, and panning the map causes lots of tearing. An error message appears in the console repeatedly.

Steps to reproduce

  1. Go to Farwell, Texas, along the New Mexico–Texas border.
  2. Select the boundary way and pan the map around.

Expected results

The map pans normally.

Actual results

The map stutters, and the following error appears repeatedly in the browser console:

Uncaught RangeError: date value is not finite in DateTimeFormat.formatRangeToParts()
    utilDisplayName util.js:205
    drawLabels labels.js:315
    call_default call.js:4
    drawEditable map.js:395
    redraw map.js:690
    Lodash 3
    map2 map.js:132
    call dispatch.js:57
    merge history.js:133
    afterLoad context.js:138
    tileCallback osm.js:1132
    handle osm.js:279
util.js:205:31

Diagnosis

The boundary relation for New Mexico Territory is tagged end_date=1912091095. This date is invalid according to ISO 8601. It should probably be 1912-01-05 based on the last member.

Anyhow, iD should not choke so hard on an invalid date. The error is thrown here when we attempt to pass an invalid Date object into Intl.DateTimeFormat.formatRangeToParts():

https://github.com/OpenHistoricalMap/iD/blob/a5a46ae34e3eef0ba5b69e7f89d7834fc3c5073d/modules/util/util.js#L205

But utilNormalizeDateString() shouldn’t even have returned a value if its date is invalid:

https://github.com/OpenHistoricalMap/iD/blob/a5a46ae34e3eef0ba5b69e7f89d7834fc3c5073d/modules/util/date.js#L69-L72

Thanks to @txemt1 for spotting and reporting this issue!