Skip to content

Commit 57925d4

Browse files
authored
Instead of checking if file exists before file read, handle exceptions from file read (#36244)
Fixes #36236
1 parent 8517df6 commit 57925d4

File tree

1 file changed

+5
-2
lines changed

1 file changed

+5
-2
lines changed

src/compiler/sys.ts

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1559,10 +1559,13 @@ namespace ts {
15591559
}
15601560

15611561
function readFileWorker(fileName: string, _encoding?: string): string | undefined {
1562-
if (!fileExists(fileName)) {
1562+
let buffer: Buffer;
1563+
try {
1564+
buffer = _fs.readFileSync(fileName);
1565+
}
1566+
catch (e) {
15631567
return undefined;
15641568
}
1565-
const buffer = _fs.readFileSync(fileName);
15661569
let len = buffer.length;
15671570
if (len >= 2 && buffer[0] === 0xFE && buffer[1] === 0xFF) {
15681571
// Big endian UTF-16 byte order mark detected. Since big endian is not supported by node.js,

0 commit comments

Comments
 (0)