Skip to content

Commit

Permalink
warn => error
Browse files Browse the repository at this point in the history
  • Loading branch information
Molly Lloyd committed Oct 5, 2017
1 parent 73b2a80 commit 6dcc1ab
Show file tree
Hide file tree
Showing 2 changed files with 10 additions and 8 deletions.
8 changes: 5 additions & 3 deletions src/style/style.js
Original file line number Diff line number Diff line change
Expand Up @@ -569,9 +569,11 @@ class Style extends Evented {
layer.setEventedParent(this, {layer: {id: id}});


const beforeIndex = before ? this._order.indexOf(before) : -1;
const index = before && beforeIndex !== -1 ? beforeIndex : this._order.length;
if (before && beforeIndex === -1) util.warnOnce(`Layer with id "${before}" does not exist on this map. Adding layer to the top of the stack.`);
const index = before ? this._order.indexOf(before) : this._order.length;
if (before && index === -1) {
this.fire('error', { message: new Error(`Layer with id "${before}" does not exist on this map.`)});
return;
}

this._order.splice(index, 0, id);

Expand Down
10 changes: 5 additions & 5 deletions test/unit/style/style.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -1006,7 +1006,7 @@ test('Style#addLayer', (t) => {
});
});

t.test('warns if before layer does not exist', (t) => {
t.test('fire error if before layer does not exist', (t) => {
const style = new Style(new StubMap());
style.loadJSON(createStyleJSON({
layers: [{
Expand All @@ -1018,13 +1018,13 @@ test('Style#addLayer', (t) => {
}]
}));
const layer = {id: 'c', type: 'background'};
t.stub(util, 'warnOnce');

style.on('style.load', () => {
style.on('error', (error)=>{
t.match(error.message, /does not exist on this map/);
t.end();
});
style.addLayer(layer, 'z');
t.deepEqual(style._order, ['a', 'b', 'c']);
t.ok(util.warnOnce.calledOnce);
t.end();
});
});

Expand Down

0 comments on commit 6dcc1ab

Please sign in to comment.