Skip to content
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

Merged
merged 2 commits into from
Feb 13, 2018

Conversation

mollymerp
Copy link
Contributor

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 in arrayIndex = -1 so it never enters the loop to check duplicate ids.

for (let i = 0; i < options.arrayIndex; i++) {
const otherLayer = style.layers[i];
if (unbundle(otherLayer.id) === layerId) {
errors.push(new ValidationError(key, layer.id, `duplicate layer id "${layer.id}", previously used at line ${otherLayer.id.__line__}`));
}
}

Launch Checklist

  • briefly describe the changes in this PR
  • write tests for all new functionality
  • document any changes to public APIs
  • post benchmark scores
  • manually test the debug page

@@ -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`)});
Copy link
Contributor

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 ?

Copy link
Contributor

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.

Copy link
Contributor Author

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)

Copy link
Contributor Author

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 😬

@@ -992,20 +992,19 @@ test('Style#addLayer', (t) => {
});

t.test('emits error on duplicates', (t) => {
t.stub(console, 'error');
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Is this necessary?

Copy link
Contributor Author

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!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

addLayer doesn't enforce id uniqueness
3 participants