mapbox / mapbox/mapbox-gl-js

setData() with invalid GeoJSON fails in two different ways, or doesn't fail

Open
#10,043 0 comments 0 reactions 0 assignees View on GitHub

Nobody has claimed this yet.

bug :lady_beetle:
Dominant language
TypeScript
Stars
12.4k
Forks
2.4k
PR merge metrics
No merged PRs in 30d

Description

**mapbox-gl-js version**: 1.6.1

**browser**:

### Steps to Trigger Behavior

```js
map.getSource('mygeojson').setData({ not: 'geojson'})

Object { message: "Input data is not a valid GeoJSON object.", stack: "" }
mapbox-gl.js:29

map.getSource('mygeojson').setData({ type: 'Point'})

Object { message: "e is undefined", stack: "" }
mapbox-gl.js:29

map.getSource('mygeojson').setData({ type: 'Point', coordinates: { lng: 30, lat: 20 }})
/* no error thrown, data is actually saved but doesn't display */
```

So, yeah. This is quite odd. Depending on exactly what is wrong with the GeoJSON that you try to set either:

1. You get a nice exception with a message.
2. You get an exception with no message.
3. You get no exception at all, and the data is actually saved, but simply fails to display anything.

The third case is particularly nasty. Took me quite a while to realise what I was doing wrong.

### Expected behaviour

The first exception thrown in all three cases.

Contributor guide

Open the contributing guide

First steps

  1. Read the whole issue, then the project's contributing guide.
  2. Comment on the issue to say you are picking it up — it saves two people doing the same work.
  3. Fork the repository and make your change on a branch.
  4. Open a pull request that references the issue number.

Research direction

Start at the GeoJSON source setData() entry point and reproduce the three invalid payloads shown in the issue. Trace their validation paths and add or update the relevant tests so every malformed input raises a consistent, useful exception rather than being silently accepted.

Written by the indexing model from the issue text.

Assessment

Tech stack
javascript, typescript
Domain
frontend
Issue type
Bug
Difficulty
3/5
Estimated time
1-2 days
Activity status
Stale
Clarity
Mostly clear
Newbie friendliness
45/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.