-
Notifications
You must be signed in to change notification settings - Fork 2.2k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
fix duplicate layer test, enforce layer id uniqueness #6147
Conversation
@@ -521,6 +521,11 @@ class Style extends Evented { | |||
|
|||
const id = layerObject.id; | |||
|
|||
if (this.getLayer(id)) { | |||
this.fire('error', {error: new Error(`Layer with id "${id}" already exists on this map`)}); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Map.addSource
will throw an error when attempting to add a source with a duplicate ID. Is there a reason to fire an error event instead of throwing for addLayer
?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Firing an event is correct; see #3879.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
We made a decision awhile back to emit errors across the board instead of throwing #3879 (comment)
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
whoops didn't reload and see john's comment 😬
test/unit/style/style.test.js
Outdated
@@ -992,20 +992,19 @@ test('Style#addLayer', (t) => { | |||
}); | |||
|
|||
t.test('emits error on duplicates', (t) => { | |||
t.stub(console, 'error'); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Is this necessary?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
hmm I guess not! left over from earlier debugging I think. removed!
fix #5989
the test that was supposed to verify this was erroneously passing due to an extra
t.end()
and validation in validate_layer doesn't work because we're passing inarrayIndex = -1
so it never enters the loop to check duplicate ids.mapbox-gl-js/src/style-spec/validate/validate_layer.js
Lines 27 to 32 in e077b78
Launch Checklist