Skip to content

fix(geojson-layer): add null-safety checks to prevent crashes on malformed features (#2383)#3337

Open
pierreeurope wants to merge 1 commit intokeplergl:masterfrom
pierreeurope:fix/geojson-null-safety-2383
Open

fix(geojson-layer): add null-safety checks to prevent crashes on malformed features (#2383)#3337
pierreeurope wants to merge 1 commit intokeplergl:masterfrom
pierreeurope:fix/geojson-null-safety-2383

Conversation

@pierreeurope
Copy link
Copy Markdown
Contributor

Summary

Adds defensive null checks in geojson-utils to prevent "Cannot read properties of undefined" crashes when processing GeoJSON data with null or malformed features.

Problem

When loading CSV data with a geojson column, certain rows may contain empty, null, or malformed geometry data. This causes crashes like:

Cannot read properties of undefined (reading 'type')

The dataToFeature array can contain null entries for rows where geometry parsing failed, but some code paths accessed properties without checking for null first.

Changes

src/layers/src/geojson-layer/geojson-utils.ts

  1. applyFiltersToTableColumns: Added null check for feature, feature.geometry, and feature.geometry.coordinates before iterating coordinates. Previously, the code accessed feature.geometry.coordinates before checking if feature was truthy (the check was in the wrong order on the next line).

  2. parseGeoJsonRawFeature: Added check for empty normalized.features array to prevent accessing features[0] on an empty array.

  3. getGeojsonLayerMeta: Used optional chaining for center() result geometry access, since the turf center function could theoretically return unexpected results for degenerate geometries.

Closes #2383

…ormed features (keplergl#2383)

- Add null check for feature, feature.geometry, and feature.geometry.coordinates
  in applyFiltersToTableColumns before accessing coordinates (fixes crash when
  dataToFeature contains null entries)
- Fix logic error where feature was checked for truthiness AFTER already
  accessing feature.geometry
- Add empty features array check in parseGeoJsonRawFeature normalization
- Use optional chaining for center() geometry access

Closes keplergl#2383

Signed-off-by: pierreeurope <pierre.europe@pm.me>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

[Bug] Cannot read properties of undefined (reading 'type')

1 participant