From d3822534c4a0d2d4af6bc0179ae83b5a29d1076b Mon Sep 17 00:00:00 2001 From: Merlin Beutlberger Date: Mon, 2 Dec 2024 14:20:27 +0100 Subject: [PATCH] [FIX] fileUtils: Properly handle exceptions from fs.stats 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 7bde334..f218adb 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 instanceof Error) { + if (err.code === "ENOENT") { // "File or directory does not exist" + return resolve(null); + } else { + return reject(err); + } + } + resolve(stat ? {path: filePath, stat} : null); }); }); }