From 9b8d376c8ed6cf7586610f842de0b64f54a75f85 Mon Sep 17 00:00:00 2001 From: Lucas Wojciechowski Date: Mon, 11 Jul 2016 16:53:57 -0700 Subject: [PATCH] Don't silently drop error events fixes #2447 --- js/util/evented.js | 9 ++++++++- test/js/style/style.test.js | 8 ++++++++ test/js/ui/map.test.js | 6 +++--- 3 files changed, 19 insertions(+), 4 deletions(-) diff --git a/js/util/evented.js b/js/util/evented.js index 53601daf9fe..9554859c3af 100644 --- a/js/util/evented.js +++ b/js/util/evented.js @@ -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}); diff --git a/test/js/style/style.test.js b/test/js/style/style.test.js index b7955aad044..2b2e9dfcedc 100644 --- a/test/js/style/style.test.js +++ b/test/js/style/style.test.js @@ -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'); @@ -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(); }); diff --git a/test/js/ui/map.test.js b/test/js/ui/map.test.js index 345a320999c..0f1b6bcc77b 100755 --- a/test/js/ui/map.test.js +++ b/test/js/ui/map.test.js @@ -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) { @@ -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": [{ @@ -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');