diff --git a/lib/internal/fs/promises.js b/lib/internal/fs/promises.js index 0fecb206237100..b6b4d6605d3387 100644 --- a/lib/internal/fs/promises.js +++ b/lib/internal/fs/promises.js @@ -196,11 +196,12 @@ async function copyFile(src, dest, flags) { async function open(path, flags, mode) { path = toPathIfFileURL(path); validatePath(path); + if (arguments.length < 2) flags = 'r'; + const flagsNumber = stringToFlags(flags); mode = validateMode(mode, 'mode', 0o666); return new FileHandle( await binding.openFileHandle(pathModule.toNamespacedPath(path), - stringToFlags(flags), - mode, kUsePromises)); + flagsNumber, mode, kUsePromises)); } async function read(handle, buffer, offset, length, position) { diff --git a/test/parallel/test-fs-open.js b/test/parallel/test-fs-open.js index ee5a21b3d355ad..788124825249ca 100644 --- a/test/parallel/test-fs-open.js +++ b/test/parallel/test-fs-open.js @@ -58,6 +58,13 @@ fs.open(__filename, 'r', null, common.mustCall((err) => { assert.ifError(err); })); +async function promise() { + await fs.promises.open(__filename); + await fs.promises.open(__filename, 'r'); +} + +promise().then(common.mustCall()).catch(common.mustNotCall()); + common.expectsError( () => fs.open(__filename, 'r', 'boom', common.mustNotCall()), { @@ -91,4 +98,15 @@ for (const extra of [[], ['r'], ['r', 0], ['r', 0, 'bad callback']]) { type: TypeError } ); + fs.promises.open(i, 'r') + .then(common.mustNotCall()) + .catch(common.mustCall((err) => { + common.expectsError( + () => { throw err; }, + { + code: 'ERR_INVALID_ARG_TYPE', + type: TypeError + } + ); + })); });