Skip to content
Closed
Show file tree
Hide file tree
Changes from 1 commit
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
Prev Previous commit
Next Next commit
fixup
  • Loading branch information
ronag committed Aug 12, 2020
commit fd5ca6044106d567cbdedc34c21086fce47eafdb
6 changes: 0 additions & 6 deletions doc/api/errors.md
Original file line number Diff line number Diff line change
Expand Up @@ -928,12 +928,6 @@ added: v14.0.0
Used when a feature that is not available
to the current platform which is running Node.js is used.

<a id="ERR_FS_FILE_CLOSED"></a>
### `ERR_FS_FILE_CLOSED`

An attempt has been made to use a
closed file handle.

<a id="ERR_FS_FILE_TOO_LARGE"></a>
### `ERR_FS_FILE_TOO_LARGE`

Expand Down
1 change: 0 additions & 1 deletion lib/internal/errors.js
Original file line number Diff line number Diff line change
Expand Up @@ -838,7 +838,6 @@ E('ERR_FEATURE_UNAVAILABLE_ON_PLATFORM',
'The feature %s is unavailable on the current platform' +
', which is being used to run Node.js',
TypeError);
E('ERR_FS_FILE_CLOSED', 'File is closed', Error);
E('ERR_FS_FILE_TOO_LARGE', 'File size (%s) is greater than 2 GB', RangeError);
E('ERR_FS_INVALID_SYMLINK_TYPE',
'Symlink type must be one of "dir", "file", or "junction". Received "%s"',
Expand Down
21 changes: 12 additions & 9 deletions lib/internal/fs/promises.js
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@ const {
MathMin,
NumberIsSafeInteger,
Symbol,
Error,
Promise,
} = primordials;

Expand All @@ -28,7 +29,6 @@ const binding = internalBinding('fs');
const { Buffer } = require('buffer');
const {
ERR_FS_FILE_TOO_LARGE,
ERR_FS_FILE_CLOSED,
ERR_INVALID_ARG_TYPE,
ERR_INVALID_ARG_VALUE,
ERR_METHOD_NOT_IMPLEMENTED
Expand Down Expand Up @@ -158,15 +158,14 @@ class FileHandle extends JSTransferable {
}
Comment thread
ronag marked this conversation as resolved.

this[kRefs]--;

if (this[kRefs]) {
if (this[kRefs] === 0) {
this[kFd] = -1;
this[kClosePromise] = this[kHandle].close();
} else {
this[kClosePromise] = new Promise((resolve, reject) => {
this[kCloseResolve] = resolve;
this[kCloseReject] = reject;
});
} else {
this[kFd] = -1;
this[kClosePromise] = this[kHandle].close();
}
Comment thread
ronag marked this conversation as resolved.

return this[kClosePromise];
Expand Down Expand Up @@ -194,12 +193,16 @@ class FileHandle extends JSTransferable {
}

async function fsCall(fn, handle, ...args) {
if (!(handle instanceof FileHandle)) {
if (handle[kRefs] === undefined) {
throw new ERR_INVALID_ARG_TYPE('filehandle', 'FileHandle', handle);
}

if (handle.fd === -1 || handle[kRefs] === 0) {
throw new ERR_FS_FILE_CLOSED();
if (handle.fd === -1) {
// eslint-disable-next-line no-restricted-syntax
const err = new Error('file closed');
err.code = 'EBADF';
err.syscall = fn.name;
throw err;
}

try {
Expand Down