mirror of
https://github.com/less/less.js.git
synced 2026-05-01 03:00:22 -04:00
improve error messages when failing to import for #2375
This commit is contained in:
@@ -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));
|
||||
});
|
||||
|
||||
@@ -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();
|
||||
|
||||
@@ -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');
|
||||
};
|
||||
}
|
||||
|
||||
@@ -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";
|
||||
|
||||
Reference in New Issue
Block a user