Skip to content

Commit

Permalink
Don't silently drop error events
Browse files Browse the repository at this point in the history
fixes #2447
  • Loading branch information
Lucas Wojciechowski committed Jul 20, 2016
1 parent 7ec9bbb commit 9b8d376
Show file tree
Hide file tree
Showing 3 changed files with 19 additions and 4 deletions.
9 changes: 8 additions & 1 deletion js/util/evented.js
Original file line number Diff line number Diff line change
Expand Up @@ -85,7 +85,14 @@ var Evented = {
* @returns {Object} `this`
*/
fire: function(type, data) {
if (!this.listens(type)) return this;
if (!this.listens(type)) {
// Error events are important for debugging and should not be
// silently dropped.
if (util.endsWith(type, 'error')) {
(console.trace || console.error)('Dropped "error" event: ', data);
}
return this;
}

data = util.extend({}, data);
util.extend(data, {type: type, target: this});
Expand Down
8 changes: 8 additions & 0 deletions test/js/style/style.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -433,6 +433,10 @@ test('Style#removeSource', function(t) {
style.addSource('source-id', source);
style.removeSource('source-id');

// Bind a listener to prevent fallback Evented error reporting.
source.on('error', function() {});
source.on('tile.error', function() {});

source.fire('load');
source.fire('error');
source.fire('change');
Expand Down Expand Up @@ -689,6 +693,10 @@ test('Style#removeLayer', function(t) {
style.on('load', function() {
var layer = style._layers.background;
style.removeLayer('background');

// Bind a listener to prevent fallback Evented error reporting.
layer.on('error', function() {});

layer.fire('error', {mapbox: true});
t.end();
});
Expand Down
6 changes: 3 additions & 3 deletions test/js/ui/map.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -150,7 +150,6 @@ test('Map', function(t) {
style.fire('tile.add');
style.fire('tile.error');
style.fire('tile.remove');
style.fire('layer.error');
});

t.test('can be called more than once', function(t) {
Expand Down Expand Up @@ -750,7 +749,7 @@ test('Map', function(t) {
"sources": {
"mapbox://mapbox.satellite": {
"type": "raster",
"tiles": ["local://tiles/{z}-{x}-{y}.png"]
"tiles": ["http://example.com/{z}/{x}/{y}.png"]
}
},
"layers": [{
Expand All @@ -764,8 +763,9 @@ test('Map', function(t) {
}
});

// We're faking tiles
// Suppress errors because we're not loading tiles from a real URL.
map.off('tile.error', map.onError);
map.on('tile.error', function() {});

map.on('style.load', function () {
map.setLayoutProperty('satellite', 'visibility', 'visible');
Expand Down

0 comments on commit 9b8d376

Please sign in to comment.