Skip to content

Commit fd5ca60

Browse files
committed
fixup
1 parent 6a3c7bb commit fd5ca60

File tree

3 files changed

+12
-16
lines changed

3 files changed

+12
-16
lines changed

doc/api/errors.md

Lines changed: 0 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -928,12 +928,6 @@ added: v14.0.0
928928
Used when a feature that is not available
929929
to the current platform which is running Node.js is used.
930930

931-
<a id="ERR_FS_FILE_CLOSED"></a>
932-
### `ERR_FS_FILE_CLOSED`
933-
934-
An attempt has been made to use a
935-
closed file handle.
936-
937931
<a id="ERR_FS_FILE_TOO_LARGE"></a>
938932
### `ERR_FS_FILE_TOO_LARGE`
939933

lib/internal/errors.js

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -838,7 +838,6 @@ E('ERR_FEATURE_UNAVAILABLE_ON_PLATFORM',
838838
'The feature %s is unavailable on the current platform' +
839839
', which is being used to run Node.js',
840840
TypeError);
841-
E('ERR_FS_FILE_CLOSED', 'File is closed', Error);
842841
E('ERR_FS_FILE_TOO_LARGE', 'File size (%s) is greater than 2 GB', RangeError);
843842
E('ERR_FS_INVALID_SYMLINK_TYPE',
844843
'Symlink type must be one of "dir", "file", or "junction". Received "%s"',

lib/internal/fs/promises.js

Lines changed: 12 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,7 @@ const {
1414
MathMin,
1515
NumberIsSafeInteger,
1616
Symbol,
17+
Error,
1718
Promise,
1819
} = primordials;
1920

@@ -28,7 +29,6 @@ const binding = internalBinding('fs');
2829
const { Buffer } = require('buffer');
2930
const {
3031
ERR_FS_FILE_TOO_LARGE,
31-
ERR_FS_FILE_CLOSED,
3232
ERR_INVALID_ARG_TYPE,
3333
ERR_INVALID_ARG_VALUE,
3434
ERR_METHOD_NOT_IMPLEMENTED
@@ -158,15 +158,14 @@ class FileHandle extends JSTransferable {
158158
}
159159

160160
this[kRefs]--;
161-
162-
if (this[kRefs]) {
161+
if (this[kRefs] === 0) {
162+
this[kFd] = -1;
163+
this[kClosePromise] = this[kHandle].close();
164+
} else {
163165
this[kClosePromise] = new Promise((resolve, reject) => {
164166
this[kCloseResolve] = resolve;
165167
this[kCloseReject] = reject;
166168
});
167-
} else {
168-
this[kFd] = -1;
169-
this[kClosePromise] = this[kHandle].close();
170169
}
171170

172171
return this[kClosePromise];
@@ -194,12 +193,16 @@ class FileHandle extends JSTransferable {
194193
}
195194

196195
async function fsCall(fn, handle, ...args) {
197-
if (!(handle instanceof FileHandle)) {
196+
if (handle[kRefs] === undefined) {
198197
throw new ERR_INVALID_ARG_TYPE('filehandle', 'FileHandle', handle);
199198
}
200199

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

205208
try {

0 commit comments

Comments
 (0)