Skip to content

Commit e9a75a8

Browse files
committed
in try_read_file_sync - treat ENOTDIR as ENOENT
ENOTDIR is relevant for cases where a directory in the middle of the path is a file and not a directory Signed-off-by: Danny Zaken <dannyzaken@gmail.com>
1 parent 9dd0dfd commit e9a75a8

File tree

1 file changed

+6
-1
lines changed

1 file changed

+6
-1
lines changed

src/util/fs_utils.js

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -142,14 +142,19 @@ function try_read_file_sync(file_name) {
142142
try {
143143
return fs.readFileSync(file_name, 'utf8');
144144
} catch (err) {
145-
if (err.code === 'ENOENT') {
145+
if (is_not_exist_err_code(err)) {
146146
// file does not exist
147147
return;
148148
}
149149
throw err;
150150
}
151151
}
152152

153+
// returns true if the error is ENOENT or ENOTDIR
154+
// ENOTDIR is relevant for cases where a directory in the middle of the path is a file and not a directory
155+
function is_not_exist_err_code(err) {
156+
return err && (err.code === 'ENOENT' || err.code === 'ENOTDIR');
157+
}
153158

154159
// returns the first line in the file that contains the substring
155160
async function find_line_in_file(file_name, line_sub_string) {

0 commit comments

Comments
 (0)