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: ERR_FS_FILE_CLOSED
  • Loading branch information
ronag committed Aug 12, 2020
commit 6a3c7bb8273ca07b10f2fd466c25c163c1135e19
6 changes: 6 additions & 0 deletions doc/api/errors.md
Original file line number Diff line number Diff line change
Expand Up @@ -928,6 +928,12 @@ 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: 1 addition & 0 deletions lib/internal/errors.js
Original file line number Diff line number Diff line change
Expand Up @@ -838,6 +838,7 @@ 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
9 changes: 6 additions & 3 deletions lib/internal/fs/promises.js
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,7 @@ 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 @@ -193,11 +194,14 @@ class FileHandle extends JSTransferable {
}

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

if (handle.fd === -1 || handle[kRefs] === 0) {
throw new ERR_FS_FILE_CLOSED();
}

try {
handle[kRefs]++;
return await fn(handle, ...args);
Expand Down Expand Up @@ -483,7 +487,6 @@ async function unlink(path) {
}

async function fchmod(handle, mode) {
validateFileHandle(handle);
mode = parseFileMode(mode, 'mode');
return binding.fchmod(handle.fd, mode, kUsePromises);
}
Expand Down