mapbox / mapbox/mapbox-gl-draw

If LineString.getCoordinate is called with an invalid index an unclear error is thrown

Open
#1,553 1 comment 0 reactions 0 assignees View on GitHub
auto-triaged bug
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

Image

(or worse in firefox)
Image

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

Open the contributing 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

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.