setData() with invalid GeoJSON fails in two different ways, or doesn't fail
Nobody has claimed this yet.
- 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
First steps
- Read the whole issue, then the project's contributing guide.
- Comment on the issue to say you are picking it up — it saves two people doing the same work.
- Fork the repository and make your change on a branch.
- 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