Much better error reporting, did you mean

master-mapnik-geometry-type
Tom MacWright 12 years ago
parent 45657268f9
commit e7658c618e

@ -1,4 +1,5 @@
(function(tree) {
var _ = require('underscore');
tree.Call = function Call(name, args, index) {
this.is = 'call';
@ -52,8 +53,17 @@ tree.Call.prototype = {
} else {
var fn = tree.Reference.mapnikFunction(this.name);
if (!fn) {
var functions = tree.Reference.mapnikFunctions();
// cheap closest, needs improvement.
var name_array = this.name.split('');
var mean = functions.map(function(f) {
return [f[0], _.intersection(name_array, f[0].split('')).length, f[1]];
}).sort(function(a, b) {
return b[1] - a[1];
});
env.error({
message: 'unknown function ' + this.name,
message: 'unknown function ' + this.name + '(), did you mean ' +
mean[0][0] + '(' + mean[0][2] + ')',
index: this.index,
type: 'runtime',
filename: this.filename
@ -65,7 +75,7 @@ tree.Call.prototype = {
}
if (fn[1] !== args.length) {
env.error({
message: 'function ' + this.name + ' takes ' +
message: 'function ' + this.name + '() takes ' +
fn[1] + ' arguments and was given ' + args.length,
index: this.index,
type: 'runtime',

@ -76,7 +76,7 @@ tree.Reference.symbolizer = function(selector) {
* For transform properties and image-filters,
* mapnik has its own functions.
*/
tree.Reference.mapnikFunction = function(name) {
tree.Reference.mapnikFunctions = function() {
var functions = [];
for (var i in tree.Reference.data.symbolizers) {
for (var j in tree.Reference.data.symbolizers[i]) {
@ -85,7 +85,15 @@ tree.Reference.mapnikFunction = function(name) {
}
}
}
return _.find(functions, function(f) {
return functions;
};
/*
* For transform properties and image-filters,
* mapnik has its own functions.
*/
tree.Reference.mapnikFunction = function(name) {
return _.find(this.mapnikFunctions(), function(f) {
return f[0] === name;
});
};

@ -0,0 +1,15 @@
{
"srs": "+proj=merc +a=6378137 +b=6378137 +lat_ts=0.0 +lon_0=0.0 +x_0=0.0 +y_0=0.0 +k=1.0 +units=m +nadgrids=@null +wktext +no_defs +over",
"Stylesheet": [
"function_args.mss"
],
"Layer": [{
"id": "world",
"name": "world",
"srs": "+proj=merc +a=6378137 +b=6378137 +lat_ts=0.0 +lon_0=0.0 +x_0=0.0 +y_0=0.0 +k=1.0 +units=m +nadgrids=@null +wktext +no_defs +over",
"Datasource": {
"file": "http://tilemill-data.s3.amazonaws.com/test_data/shape_demo.zip",
"type": "shape"
}
}]
}

@ -0,0 +1,4 @@
#world {
point-transform: scale(2, 2);
image-filters: agg-stack-blu(2, 1);
}

@ -0,0 +1 @@
function_args.mss:3:38 unknown function agg-stack-blu(), did you mean agg-stack-blur(2)
Loading…
Cancel
Save