From 45657268f90b0bd6f564d8da2a17a46d46e1f2b5 Mon Sep 17 00:00:00 2001 From: Tom MacWright Date: Mon, 8 Oct 2012 18:39:09 -0400 Subject: [PATCH] More verbose and informative error messages, especially when dealing with keyword values. Fixes #109 --- lib/carto/tree/rule.js | 13 ++++++++++--- test/errorhandling/invalid_value.mss | 4 +++- test/errorhandling/invalid_value.result | 3 ++- 3 files changed, 15 insertions(+), 5 deletions(-) diff --git a/lib/carto/tree/rule.js b/lib/carto/tree/rule.js index d63a9ba..bf883d9 100644 --- a/lib/carto/tree/rule.js +++ b/lib/carto/tree/rule.js @@ -58,13 +58,20 @@ tree.Rule.prototype.toXML = function(env, content, sep, format) { filename: this.filename }); } else { + var typename; + if (tree.Reference.selector(this.name).validate) { + typename = tree.Reference.selector(this.name).validate; + } else if (typeof tree.Reference.selector(this.name).type === 'object') { + typename = 'keyword (options: ' + tree.Reference.selector(this.name).type.join(', ') + ')'; + } else { + typename = tree.Reference.selector(this.name).type; + } return env.error({ message: 'Invalid value for ' + this.name + - ', a valid ' + - (tree.Reference.selector(this.name).validate || - tree.Reference.selector(this.name).type) + + ', the type ' + typename + ' is expected. ' + this.value + + ' (of type ' + this.value.value[0].is + ') ' + ' was given.', index: this.index, type: 'syntax', diff --git a/test/errorhandling/invalid_value.mss b/test/errorhandling/invalid_value.mss index f210d26..181174b 100644 --- a/test/errorhandling/invalid_value.mss +++ b/test/errorhandling/invalid_value.mss @@ -1,3 +1,5 @@ #world[zoom=5] { - polygon-opacity: #f00; + text-face-name: 2; + line-rasterizer: 'full'; + text-name: 'foo'; } diff --git a/test/errorhandling/invalid_value.result b/test/errorhandling/invalid_value.result index 2a951f5..32dc5e9 100644 --- a/test/errorhandling/invalid_value.result +++ b/test/errorhandling/invalid_value.result @@ -1 +1,2 @@ -invalid_value.mss:2:2 Invalid value for polygon-opacity, a valid float is expected. #ff0000 was given. +invalid_value.mss:2:2 Invalid value for text-face-name, the type font is expected. 2 (of type float) was given. +invalid_value.mss:3:2 Invalid value for line-rasterizer, the type keyword (options: full, fast) is expected. full (of type string) was given.