Skip to content

Commit f90f58a

Browse files
committed
[FIX] fileUtils: Properly handle exceptions from fs.stat
Do not assume every exception is caused by a missing file
1 parent d5faadc commit f90f58a

File tree

1 file changed

+8
-2
lines changed

1 file changed

+8
-2
lines changed

lib/fileUtils.js

Lines changed: 8 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -10,8 +10,14 @@ module.exports = function(fs) {
1010
function statFile(filePath) {
1111
return new Promise(function(resolve, reject) {
1212
fs.stat(filePath, function(err, stat) {
13-
// No rejection here as it is ok if the file was not found
14-
resolve(stat ? {path: filePath, stat: stat} : null);
13+
if (err) {
14+
if (err.code === "ENOENT") { // "File or directory does not exist"
15+
return resolve(null);
16+
} else {
17+
return reject(err);
18+
}
19+
}
20+
resolve({path: filePath, stat});
1521
});
1622
});
1723
}

0 commit comments

Comments
 (0)