mapbox / mapbox/mapbox-gl-draw
If LineString.getCoordinate is called with an invalid index an unclear error is thrown
- Dominant language
- JavaScript
- Stars
- 1.1k
- Forks
- 612
- Avg merge
- 8d 9h
- Merged PRs (30d)
- 5
Description
When `JSON.parse(JSON.stringify(x))` is used to clone objects, if the object is undefined, then it'll error with
(or worse in firefox)
This probably happens everywhere that snippet shows up, but for me it happened after selecting a coordinate that didn't exist.
https://github.com/mapbox/mapbox-gl-draw/blob/1257e6313af033b93ce226a979d50634d7da7bb7/src/feature_types/line_string.js#L19-L22
Probably would be fixed if you used [structuredClone](https://developer.mozilla.org/en-US/docs/Web/API/Window/structuredClone)? I can open a PR, but idk if you'd rather return undefined or throw a clearer error.
Contributor guide
Research direction
Start in src/feature_types/line_string.js at lines 19–22 and reproduce the failure by selecting a coordinate that does not exist. Check how LineString.getCoordinate handles invalid indexes and decide, with maintainer guidance, whether the intended result is undefined or a clearer error; verify the chosen behavior in the relevant test coverage.
Written by the indexing model from the issue text.
Assessment
- Tech stack
- javascript
- Domain
- frontend, web-dev
- Issue type
- Bug
- Difficulty
- 2/5
- Estimated time
- 1-3 hours
- Activity status
- Quiet
- Clarity
- Mostly clear
- Newbie friendliness
- 52/100