Skip to content

Commit 18a635e

Browse files
committed
[js] Make open throw a nqp level exception on missing file
1 parent 48be669 commit 18a635e

File tree

1 file changed

+11
-3
lines changed
  • src/vm/js/nqp-runtime

1 file changed

+11
-3
lines changed

src/vm/js/nqp-runtime/io.js

Lines changed: 11 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -281,9 +281,17 @@ function modeToFlags(mode) {
281281
}
282282

283283
op.open = function(name, mode) {
284-
let fh = new FileHandle(fs.openSync(name, modeToFlags(mode)));
285-
fh.encoding = 'utf8';
286-
return fh;
284+
try {
285+
let fh = new FileHandle(fs.openSync(name, modeToFlags(mode)));
286+
fh.encoding = 'utf8';
287+
return fh;
288+
} catch (e) {
289+
if (e.code === 'ENOENT') {
290+
throw new NQPException(`Failed to open file ${name}: No such file or director`);
291+
} else {
292+
throw e;
293+
}
294+
}
287295
};
288296

289297
op.seekfh = function(ctx, fh, offset, whence) {

0 commit comments

Comments
 (0)