From d5faadcda2d667a95bc02110c6eefd2bd588d276 Mon Sep 17 00:00:00 2001 From: Merlin Beutlberger Date: Mon, 2 Dec 2024 13:28:34 +0100 Subject: [PATCH 1/2] [FIX] fileUtils: Correctly provide stat property on readFile result The fileInfo object contains property 'stat', not 'stats'. I couldn't find any usage of the property on the readFile result though. --- lib/fileUtils.js | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/lib/fileUtils.js b/lib/fileUtils.js index 63c80027..7bde334a 100644 --- a/lib/fileUtils.js +++ b/lib/fileUtils.js @@ -57,7 +57,7 @@ module.exports = function(fs) { content: content, path: fileInfo.path, localPath: lessInputPath, - stats: fileInfo.stats + stat: fileInfo.stat }); } }); From f90f58aaae9e60d520e1ce4863c6f183927475cc Mon Sep 17 00:00:00 2001 From: Merlin Beutlberger Date: Mon, 2 Dec 2024 14:20:27 +0100 Subject: [PATCH 2/2] [FIX] fileUtils: Properly handle exceptions from fs.stat Do not assume every exception is caused by a missing file --- lib/fileUtils.js | 10 ++++++++-- 1 file changed, 8 insertions(+), 2 deletions(-) diff --git a/lib/fileUtils.js b/lib/fileUtils.js index 7bde334a..2f551ff9 100644 --- a/lib/fileUtils.js +++ b/lib/fileUtils.js @@ -10,8 +10,14 @@ module.exports = function(fs) { function statFile(filePath) { return new Promise(function(resolve, reject) { fs.stat(filePath, function(err, stat) { - // No rejection here as it is ok if the file was not found - resolve(stat ? {path: filePath, stat: stat} : null); + if (err) { + if (err.code === "ENOENT") { // "File or directory does not exist" + return resolve(null); + } else { + return reject(err); + } + } + resolve({path: filePath, stat}); }); }); }