Merge pull request #543 from CartoDB/turbo-carto-multiple-errors

Return multiple turbo-carto errors
This commit is contained in:
Raul Ochoa 2016-07-06 00:43:00 +02:00 committed by GitHub
commit 870468ddf7
3 changed files with 68 additions and 6 deletions

View File

@ -4,6 +4,9 @@
Released 2016-mm-dd
Enhancements:
- Return multiple turbo-carto errors #541.
Announcements:
- Upgrades turbo-carto to [0.13.0](https://github.com/CartoDB/turbo-carto/releases/tag/0.13.0).

View File

@ -32,12 +32,22 @@ TurboCartoAdapter.prototype.getMapConfig = function (user, requestMapConfig, par
parseCartoQueue.defer(self._parseCartoCss.bind(self), user, params, layer, index, layerId);
});
parseCartoQueue.awaitAll(function (err, layers) {
parseCartoQueue.awaitAll(function (err, results) {
if (err) {
return callback(err);
}
requestMapConfig.layers = layers;
var errors = results.reduce(function(errors, result) {
if (result.error) {
errors.push(result.error);
}
return errors;
}, []);
if (errors.length > 0) {
return callback(errors);
}
requestMapConfig.layers = results.map(function(result) { return result.layer; });
return callback(null, requestMapConfig);
});
@ -70,7 +80,7 @@ var tokensQueryTpl = dot.template([
TurboCartoAdapter.prototype._parseCartoCss = function (username, params, layer, layerIndex, layerId, callback) {
if (!shouldParseLayerCartocss(layer)) {
return callback(null, layer);
return callback(null, { layer: layer });
}
var pg = new PSQL(dbParamsFromReqParams(params));
@ -88,14 +98,14 @@ TurboCartoAdapter.prototype._parseCartoCss = function (username, params, layer,
context: err.context
};
return callback(error);
return callback(null, { error: error });
}
// Try to continue in the rest of the cases
if (cartocss) {
layer.options.cartocss = cartocss;
}
return callback(null, layer);
return callback(null, { layer: layer });
}
var layerSql = layer.options.sql;
@ -107,7 +117,7 @@ TurboCartoAdapter.prototype._parseCartoCss = function (username, params, layer,
if (err) {
var error = new Error('turbo-carto: ' + err.message);
error.type = 'turbo-carto';
return callback(error);
return processCallback(error);
}
resultSet = resultSet || {};

View File

@ -138,4 +138,53 @@ describe('turbo-carto error cases', function() {
done();
});
});
it('should return multiple errors', function(done) {
var multipleErrorsMapConfig = {
"version": "1.4.0",
"layers": [
{
"type": 'mapnik',
"options": {
"cartocss_version": '2.3.0',
"sql": 'SELECT * FROM populated_places_simple_reduced',
"cartocss": createCartocss(null, 'ramp([wadus_column], (red, green, blue))')
}
},
{
"type": 'mapnik',
"options": {
"cartocss_version": '2.3.0',
"sql": 'SELECT * FROM populated_places_simple_reduced',
"cartocss": createCartocss('ramp([invalid_column], (red, green, blue))')
}
}
]
};
this.testClient = new TestClient(multipleErrorsMapConfig);
this.testClient.getLayergroup(ERROR_RESPONSE, function(err, layergroup) {
assert.ok(!err, err);
assert.ok(layergroup.hasOwnProperty('errors'));
assert.equal(layergroup.errors_with_context.length, 2);
assert.equal(layergroup.errors_with_context[0].type, 'layer');
assert.equal(layergroup.errors_with_context[0].subtype, 'turbo-carto');
assert.ok(layergroup.errors_with_context[0].message.match(/^turbo-carto/));
assert.ok(layergroup.errors_with_context[0].message.match(/unable\sto\scompute\sramp/i));
assert.ok(layergroup.errors_with_context[0].message.match(/wadus_column/));
assert.equal(layergroup.errors_with_context[0].layer.id, 'layer0');
assert.equal(layergroup.errors_with_context[1].type, 'layer');
assert.equal(layergroup.errors_with_context[1].subtype, 'turbo-carto');
assert.ok(layergroup.errors_with_context[1].message.match(/^turbo-carto/));
assert.ok(layergroup.errors_with_context[1].message.match(/unable\sto\scompute\sramp/i));
assert.ok(layergroup.errors_with_context[1].message.match(/invalid_column/));
assert.equal(layergroup.errors_with_context[1].layer.id, 'layer1');
done();
});
});
});