diff --git a/lib/fs.js b/lib/fs.js index 4862b8cd698018..fc9b630e81208c 100644 --- a/lib/fs.js +++ b/lib/fs.js @@ -632,7 +632,7 @@ function read(fd, buffer, offsetOrOptions, length, position, callback) { } ({ offset = 0, - length = buffer.byteLength - offset, + length = buffer?.byteLength - offset, position = null, } = params ?? kEmptyObject); } diff --git a/test/parallel/test-fs-read.js b/test/parallel/test-fs-read.js index 2b3dab4f243b90..966185c5138d63 100644 --- a/test/parallel/test-fs-read.js +++ b/test/parallel/test-fs-read.js @@ -79,7 +79,7 @@ assert.throws( assert.throws( () => fs.read(fd, { buffer: null }, common.mustNotCall()), - /TypeError: Cannot read properties of null \(reading 'byteLength'\)/, + { code: 'ERR_INVALID_ARG_TYPE' }, 'throws when options.buffer is null' );