[Pkg-javascript-commits] [less.js] 191/285: improve error reporting

Jonas Smedegaard dr at jones.dk
Mon Oct 26 23:23:53 UTC 2015


This is an automated email from the git hooks/post-receive script.

js pushed a commit to annotated tag v2.0.0
in repository less.js.

commit 845ec72131c0d28e3c6447e2ac5f40bc5fe35cf1
Author: Luke Page <luke.a.page at gmail.com>
Date:   Sun Oct 19 16:48:04 2014 +0100

    improve error reporting
---
 lib/less-browser/browser.js         |  2 +-
 lib/less-browser/error-reporting.js | 10 ++++++----
 lib/less-browser/index.js           |  1 -
 lib/less-browser/log-listener.js    |  4 ++--
 lib/less/functions/color.js         |  2 +-
 lib/less/parser/parser.js           |  2 +-
 lib/less/tree/expression.js         | 11 +++++++----
 lib/less/tree/value.js              |  3 +++
 test/browser/common.js              |  6 ++++--
 9 files changed, 25 insertions(+), 16 deletions(-)

diff --git a/lib/less-browser/browser.js b/lib/less-browser/browser.js
index c289a15..fdb1d06 100644
--- a/lib/less-browser/browser.js
+++ b/lib/less-browser/browser.js
@@ -50,7 +50,7 @@ module.exports = {
             try {
                 css.styleSheet.cssText = styles;
             } catch (e) {
-                throw new(Error)("Couldn't reassign styleSheet.cssText.");
+                throw new Error("Couldn't reassign styleSheet.cssText.");
             }
         }
     }
diff --git a/lib/less-browser/error-reporting.js b/lib/less-browser/error-reporting.js
index 54d23c2..a358d13 100644
--- a/lib/less-browser/error-reporting.js
+++ b/lib/less-browser/error-reporting.js
@@ -30,8 +30,9 @@ module.exports = function(window, less, options) {
             errorline(e, 2, '');
             content += 'on line ' + e.line + ', column ' + (e.column + 1) + ':</p>' +
                 '<ul>' + errors.join('') + '</ul>';
-        } else if (e.stack) {
-            content += '<br/>' + e.stack.split('\n').slice(1).join('<br/>');
+        }
+        if (e.stack && (e.extract || options.logLevel >= 4)) {
+            content += '<br/>Stack Trace</br />' + e.stack.split('\n').slice(1).join('<br/>');
         }
         elem.innerHTML = content;
 
@@ -155,8 +156,9 @@ module.exports = function(window, less, options) {
             errorline(e, 2, '');
             content += 'on line ' + e.line + ', column ' + (e.column + 1) + ':\n' +
                 errors.join('\n');
-        } else if (e.stack) {
-            content += e.stack;
+        }
+        if (e.stack && (e.extract || options.logLevel >= 4)) {
+            content += '\nStack Trace\n' + e.stack;
         }
         less.logger.error(content);
     }
diff --git a/lib/less-browser/index.js b/lib/less-browser/index.js
index f90d260..6cb3549 100644
--- a/lib/less-browser/index.js
+++ b/lib/less-browser/index.js
@@ -25,7 +25,6 @@ environment.addFileManager(fileManager);
 less.FileManager = FileManager;
 
 require("./log-listener")(less, options);
-//var utils = require("./utils");
 var errors = require("./error-reporting")(window, less, options);
 var browser = require("./browser");
 var cache = options.cache || require("./cache")(window, options, less.logger);
diff --git a/lib/less-browser/log-listener.js b/lib/less-browser/log-listener.js
index 9806c99..199a499 100644
--- a/lib/less-browser/log-listener.js
+++ b/lib/less-browser/log-listener.js
@@ -8,10 +8,10 @@ module.exports = function(less, options) {
     // The amount of logging in the javascript console.
     // 3 - Debug, information and errors
     // 2 - Information and errors
-    //  1 - Errors
+    // 1 - Errors
     // 0 - None
     // Defaults to 2
-    options.logLevel = typeof(options.logLevel) !== 'undefined' ? options.logLevel : (options.env === 'development' ?  logLevel_debug : logLevel_error);
+    options.logLevel = typeof(options.logLevel) !== 'undefined' ? options.logLevel : (options.env === 'development' ?  logLevel_info : logLevel_error);
 
     if (!options.loggers) {
         options.loggers = [{
diff --git a/lib/less/functions/color.js b/lib/less/functions/color.js
index ebdd042..5355823 100644
--- a/lib/less/functions/color.js
+++ b/lib/less/functions/color.js
@@ -18,7 +18,7 @@ function number(n) {
         return n;
     } else {
         throw {
-            error: "RuntimeError",
+            type: "Argument",
             message: "color functions take numbers as parameters"
         };
     }
diff --git a/lib/less/parser/parser.js b/lib/less/parser/parser.js
index b04392b..099d346 100644
--- a/lib/less/parser/parser.js
+++ b/lib/less/parser/parser.js
@@ -113,7 +113,7 @@ var Parser = function Parser(context, imports, fileInfo) {
             // output. The callback is called when the input is parsed.
             try {
                 parserInput.start(str, context.chunkInput, function fail(msg, index) {
-                    throw new(LessError)({
+                    throw LessError({
                         index: index,
                         type: 'Parse',
                         message: msg,
diff --git a/lib/less/tree/expression.js b/lib/less/tree/expression.js
index 59e8a40..3083e3b 100644
--- a/lib/less/tree/expression.js
+++ b/lib/less/tree/expression.js
@@ -2,13 +2,16 @@ var Node = require("./node"),
     Paren = require("./paren"),
     Comment = require("./comment");
 
-var Expression = function (value) { this.value = value; };
+var Expression = function (value) {
+    this.value = value;
+    if (!value) {
+        throw new Error("Expression requires a array parameter");
+    }
+};
 Expression.prototype = new Node();
 Expression.prototype.type = "Expression";
 Expression.prototype.accept = function (visitor) {
-    if (this.value) {
-        this.value = visitor.visitArray(this.value);
-    }
+    this.value = visitor.visitArray(this.value);
 };
 Expression.prototype.eval = function (context) {
     var returnValue,
diff --git a/lib/less/tree/value.js b/lib/less/tree/value.js
index ebdff00..ee31c83 100644
--- a/lib/less/tree/value.js
+++ b/lib/less/tree/value.js
@@ -2,6 +2,9 @@ var Node = require("./node");
 
 var Value = function (value) {
     this.value = value;
+    if (!value) {
+        throw new Error("Value requires an array argument");
+    }
 };
 Value.prototype = new Node();
 Value.prototype.type = "Value";
diff --git a/test/browser/common.js b/test/browser/common.js
index 1ca4e7a..4e9ea54 100644
--- a/test/browser/common.js
+++ b/test/browser/common.js
@@ -103,7 +103,8 @@ var testErrorSheet = function (sheet) {
                         return lineNo + " ";
                     })
                     .replace(/\n\s*in /g, " in ")
-                    .replace("\n\n", "\n");
+                    .replace("\n\n", "\n")
+                    .replace(/\nStack Trace\n[\s\S]*/, "");
                 errorFile
                     .then(function (errorTxt) {
                         errorTxt = errorTxt
@@ -128,7 +129,8 @@ var testErrorSheetConsole = function (sheet) {
             errorHref = lessHref.replace(/.less$/, ".txt"),
             errorFile = loadFile(errorHref),
             actualErrorElement = document.getElementById(id),
-            actualErrorMsg = logMessages[logMessages.length - 1];
+            actualErrorMsg = logMessages[logMessages.length - 1]
+                .replace(/\nStack Trace\n[\s\S]*/, "");
 
         describe("the error", function () {
             expect(actualErrorElement).toBe(null);

-- 
Alioth's /usr/local/bin/git-commit-notice on /srv/git.debian.org/git/pkg-javascript/less.js.git



More information about the Pkg-javascript-commits mailing list