From 525fba6405d7a34f8eb3872ab91a11bcf6870643 Mon Sep 17 00:00:00 2001 From: Tim Schaub Date: Thu, 13 Apr 2017 05:54:51 -0600 Subject: [PATCH 1/3] Assume latest if no ol.VERSION --- src/ol/assertionerror.js | 5 +++-- test/spec/ol/assertionerror.test.js | 5 ++++- 2 files changed, 7 insertions(+), 3 deletions(-) diff --git a/src/ol/assertionerror.js b/src/ol/assertionerror.js index 341e623a49..2f0af35e02 100644 --- a/src/ol/assertionerror.js +++ b/src/ol/assertionerror.js @@ -13,11 +13,12 @@ goog.require('ol'); */ ol.AssertionError = function(code) { + var path = ol.VERSION ? ol.VERSION.split('-')[0] : 'latest'; + /** * @type {string} */ - this.message = 'Assertion failed. See ' + - (ol.VERSION ? 'https://openlayers.org/en/' + ol.VERSION.split('-')[0] : '') + + this.message = 'Assertion failed. See https://openlayers.org/en/' + path + '/doc/errors/#' + code + ' for details.'; /** diff --git a/test/spec/ol/assertionerror.test.js b/test/spec/ol/assertionerror.test.js index 19c18bbcd8..6ff509c588 100644 --- a/test/spec/ol/assertionerror.test.js +++ b/test/spec/ol/assertionerror.test.js @@ -6,8 +6,9 @@ goog.require('ol.AssertionError'); describe('ol.AssertionError', function() { it('generates a message', function() { var error = new ol.AssertionError(42); - expect(error.message).to.be('Assertion failed. See /doc/errors/#42 for details.'); + expect(error.message).to.be('Assertion failed. See https://openlayers.org/en/latest/doc/errors/#42 for details.'); }); + it('generates a message with a versioned url', function() { var origVersion = ol.VERSION; ol.VERSION = 'foo'; @@ -15,10 +16,12 @@ describe('ol.AssertionError', function() { expect(error.message).to.be('Assertion failed. See https://openlayers.org/en/foo/doc/errors/#42 for details.'); ol.VERSION = origVersion; }); + it('has an error code', function() { var error = new ol.AssertionError(42); expect(error.code).to.be(42); }); + it('has a name', function() { var error = new ol.AssertionError(42); expect(error.name).to.be('AssertionError'); From 4a9114cd4e17604a7902c05c7147b600902eb29f Mon Sep 17 00:00:00 2001 From: Tim Schaub Date: Thu, 13 Apr 2017 06:26:02 -0600 Subject: [PATCH 2/3] Set ol.VERSION when creating ol package --- transforms/module.js | 7 +++++++ 1 file changed, 7 insertions(+) diff --git a/transforms/module.js b/transforms/module.js index 6597dae7ea..e3c276ad41 100644 --- a/transforms/module.js +++ b/transforms/module.js @@ -1,4 +1,5 @@ const pkg = require('../package.json'); +const version = require('../package/package.json').version; const defines = { 'ol.ENABLE_WEBGL': false @@ -118,6 +119,12 @@ module.exports = function(info, api) { // store any initial comments const {comments} = root.find(j.Program).get('body', 0).node; + // replace `ol.VERSION = ''` with correct version + root.find(j.ExpressionStatement, getMemberExpressionAssignment('ol.VERSION')) + .forEach(path => { + path.value.expression.right = j.literal(version); + }); + const replacements = {}; // replace all uses of defines From 6604172c1c00be481d072bfb2030494f4d91bf73 Mon Sep 17 00:00:00 2001 From: Tim Schaub Date: Thu, 13 Apr 2017 06:37:42 -0600 Subject: [PATCH 3/3] Throw a byte-saving AssertionError --- doc/errors/index.md | 4 ++++ src/ol/collection.js | 3 ++- 2 files changed, 6 insertions(+), 1 deletion(-) diff --git a/doc/errors/index.md b/doc/errors/index.md index 5da35ba9ff..e6b14708a8 100644 --- a/doc/errors/index.md +++ b/doc/errors/index.md @@ -220,3 +220,7 @@ The `{-y}` placeholder requires a tile grid with extent. ### 57 At least 2 conditions are required. + +### 58 + +Duplicate item added to a unique collection. For example, it may be that you tried to add the same layer to a map twice. Check for calls to `map.addLayer()` or other places where the map's layer collection is modified. diff --git a/src/ol/collection.js b/src/ol/collection.js index c21bc2f867..d168cb7d16 100644 --- a/src/ol/collection.js +++ b/src/ol/collection.js @@ -6,6 +6,7 @@ goog.provide('ol.Collection'); goog.require('ol'); +goog.require('ol.AssertionError'); goog.require('ol.CollectionEventType'); goog.require('ol.Object'); goog.require('ol.events.Event'); @@ -256,7 +257,7 @@ ol.Collection.prototype.updateLength_ = function() { ol.Collection.prototype.assertUnique_ = function(elem, opt_except) { for (var i = 0, ii = this.array_.length; i < ii; ++i) { if (this.array_[i] === elem && i !== opt_except) { - throw new Error('Duplicate item added to a unique collection'); + throw new ol.AssertionError(58); } } };