[Pkg-javascript-commits] [less.js] 12/58: improve error messages when failing to import for #2375

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


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

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

commit 8ea1e880f2bf97c40038021067dcab73d01a737d
Author: Luke Page <luke.a.page at gmail.com>
Date:   Sun Jan 11 16:30:29 2015 +0000

    improve error messages when failing to import for #2375
---
 lib/less-node/file-manager.js       |  9 ++++++---
 test/browser/common.js              | 18 ++++++++++--------
 test/index.js                       | 10 ++++++----
 test/less/errors/import-missing.txt |  2 +-
 4 files changed, 23 insertions(+), 16 deletions(-)

diff --git a/lib/less-node/file-manager.js b/lib/less-node/file-manager.js
index 62829b0..56f788d 100644
--- a/lib/less-node/file-manager.js
+++ b/lib/less-node/file-manager.js
@@ -17,7 +17,8 @@ FileManager.prototype.supportsSync = function(filename, currentDirectory, option
 
 FileManager.prototype.loadFile = function(filename, currentDirectory, options, environment, callback) {
     var fullFilename,
-        data;
+        data,
+        filenamesTried = [];
 
     options = options || {};
 
@@ -30,6 +31,7 @@ FileManager.prototype.loadFile = function(filename, currentDirectory, options, e
         for (var i = 0; i < paths.length; i++) {
             try {
                 fullFilename = path.join(paths[i], filename);
+                filenamesTried.push(fullFilename);
                 fs.statSync(fullFilename);
                 break;
             } catch (e) {
@@ -38,7 +40,7 @@ FileManager.prototype.loadFile = function(filename, currentDirectory, options, e
         }
 
         if (!fullFilename) {
-            err = { type: 'File', message: "'" + filename + "' wasn't found" };
+            err = { type: 'File', message: "'" + filename + "' wasn't found. Tried - " + filenamesTried.join(",") };
         } else {
             data = fs.readFileSync(fullFilename, 'utf-8');
             result = { contents: data, filename: fullFilename};
@@ -56,6 +58,7 @@ FileManager.prototype.loadFile = function(filename, currentDirectory, options, e
                 fullFilename = path.join(paths[i], filename);
                 fs.stat(fullFilename, function (err) {
                     if (err) {
+                        filenamesTried.push(fullFilename);
                         tryPathIndex(i + 1);
                     } else {
                         fs.readFile(fullFilename, 'utf-8', function(e, data) {
@@ -66,7 +69,7 @@ FileManager.prototype.loadFile = function(filename, currentDirectory, options, e
                     }
                 });
             } else {
-                reject({ type: 'File', message: "'" + filename + "' wasn't found" });
+                reject({ type: 'File', message: "'" + filename + "' wasn't found. Tried - " + filenamesTried.join(",") });
             }
         }(0));
     });
diff --git a/test/browser/common.js b/test/browser/common.js
index 9b56c3f..5b6772d 100644
--- a/test/browser/common.js
+++ b/test/browser/common.js
@@ -145,10 +145,11 @@ var testErrorSheet = function (sheet) {
                 errorFile
                     .then(function (errorTxt) {
                         errorTxt = errorTxt
-                            .replace("{path}", "")
-                            .replace("{pathrel}", "")
-                            .replace("{pathhref}", "http://localhost:8081/test/less/errors/")
-                            .replace("{404status}", " (404)")
+                            .replace(/\{path\}/g, "")
+                            .replace(/\{pathrel\}/g, "")
+                            .replace(/\{pathhref\}/g, "http://localhost:8081/test/less/errors/")
+                            .replace(/\{404status\}/g, " (404)")
+	                        .replace(/\{node\}.*\{\/node\}/g, "")
                             .replace(/\n$/, "");
                         expect(actualErrorMsg).toEqual(errorTxt);
                         if (errorTxt == actualErrorMsg) {
@@ -177,10 +178,11 @@ var testErrorSheetConsole = function (sheet) {
         errorFile
             .then(function (errorTxt) {
                 errorTxt
-                    .replace("{path}", "")
-                    .replace("{pathrel}", "")
-                    .replace("{pathhref}", "http://localhost:8081/browser/less/")
-                    .replace("{404status}", " (404)")
+                    .replace(/\{path\}/g, "")
+                    .replace(/\{pathrel\}/g, "")
+                    .replace(/\{pathhref\}/g, "http://localhost:8081/browser/less/")
+                    .replace(/\{404status\}/g, " (404)")
+                    .replace(/\{node\}.*\{\/node\}/g, "")
                     .trim();
                 expect(actualErrorMsg).toEqual(errorTxt);
                 done();
diff --git a/test/index.js b/test/index.js
index 4f7e510..a82bc9a 100644
--- a/test/index.js
+++ b/test/index.js
@@ -6,10 +6,12 @@ var lessTest = require("./less-test"),
 function getErrorPathReplacementFunction(dir) {
     return function(input) {
         return input.replace(
-                "{path}", path.join(process.cwd(), "/test/less/" + dir + "/"))
-            .replace("{pathrel}", path.join("test", "less", dir + "/"))
-            .replace("{pathhref}", "")
-            .replace("{404status}", "")
+                /\{path\}/g, path.join(process.cwd(), "/test/less/" + dir + "/"))
+	        .replace(/\{node\}/g, "")
+	        .replace(/\{\/node\}/g, "")
+            .replace(/\{pathrel\}/g, path.join("test", "less", dir + "/"))
+            .replace(/\{pathhref\}/g, "")
+            .replace(/\{404status\}/g, "")
             .replace(/\r\n/g, '\n');
     };
 }
diff --git a/test/less/errors/import-missing.txt b/test/less/errors/import-missing.txt
index 488d154..5602b0f 100644
--- a/test/less/errors/import-missing.txt
+++ b/test/less/errors/import-missing.txt
@@ -1,3 +1,3 @@
-FileError: '{pathhref}file-does-not-exist.less' wasn't found{404status} in {path}import-missing.less on line 6, column 1:
+FileError: '{pathhref}file-does-not-exist.less' wasn't found{404status}{node}. Tried - {path}file-does-not-exist.less,{pathrel}file-does-not-exist.less,file-does-not-exist.less{/node} in {path}import-missing.less on line 6, column 1:
 5 
 6 @import "file-does-not-exist.less";

-- 
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