Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion lib/internal/fs/read/context.js
Original file line number Diff line number Diff line change
Expand Up @@ -180,7 +180,7 @@ class ReadFileContext {
close(err) {
if (this.isUserFd) {
process.nextTick(function tick(context) {
FunctionPrototypeCall(readFileAfterClose, { context }, null);
FunctionPrototypeCall(readFileAfterClose, { context }, err);
}, this);
return;
}
Expand Down
35 changes: 35 additions & 0 deletions test/parallel/test-fs-readfile-buffer-option.js
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,15 @@ function readFile(path, options) {
});
}

function readFileFd(fd, options) {
return new Promise((resolve, reject) => {
fs.readFile(fd, options, (err, data) => {
if (err) reject(err);
else resolve(data);
});
});
}

async function withFstatSizeZero(fn) {
const originalFstat = fsBinding.fstat;
fsBinding.fstat = function(...args) {
Expand Down Expand Up @@ -128,6 +137,32 @@ async function withFstatSizeZero(fn) {
code: 'ERR_INVALID_ARG_VALUE',
});

{
const fd = fs.openSync(file, 'r');
try {
const buffer = Buffer.alloc(content.length - 1);
await assert.rejects(readFileFd(fd, { buffer }), {
code: 'ERR_INVALID_ARG_VALUE',
});
} finally {
fs.closeSync(fd);
}
}

{
const fd = fs.openSync(file, 'r');
try {
await assert.rejects(readFileFd(fd, {
buffer() {
return Buffer.alloc(content.length - 1);
},
}), {
code: 'ERR_INVALID_ARG_VALUE',
});
} finally {
fs.closeSync(fd);
}
}

await withFstatSizeZero(common.mustCall(async () => {
{
Expand Down
Loading