Catch parser exception in the correct scope

This commit is contained in:
Sandro Santilli 2012-09-26 15:51:05 +02:00
parent 381806c7c7
commit 6a040acd07

View File

@ -29,6 +29,7 @@ carto.Renderer.prototype.render = function render(m, callback) {
var output = []; var output = [];
// Transform stylesheets into rulesets. // Transform stylesheets into rulesets.
try { // Parser may throw
var rulesets = _(m.Stylesheet).chain() var rulesets = _(m.Stylesheet).chain()
.map(function(s) { .map(function(s) {
// Passing the environment from stylesheet to stylesheet, // Passing the environment from stylesheet to stylesheet,
@ -36,15 +37,14 @@ carto.Renderer.prototype.render = function render(m, callback) {
env = _(env).extend({filename:s.id}); env = _(env).extend({filename:s.id});
var time = +new Date(); var time = +new Date();
// Parser may throw root = (carto.Parser(env)).parse(s.data);
try { root = (carto.Parser(env)).parse(s.data); }
catch (err) { callback(err, null); return; }
if (env.benchmark) if (env.benchmark)
console.warn('Parsing time: ' + (new Date() - time) + 'ms'); console.warn('Parsing time: ' + (new Date() - time) + 'ms');
return root.toList(env); return root.toList(env);
}) })
.flatten() .flatten()
.value(); .value();
} catch (err) { callback(err, null); return; }
// Iterate through layers and create styles custom-built // Iterate through layers and create styles custom-built
// for each of them, and apply those styles to the layers. // for each of them, and apply those styles to the layers.