Skip to content
Open
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
9 changes: 6 additions & 3 deletions doc/api/deprecations.md
Original file line number Diff line number Diff line change
Expand Up @@ -4190,6 +4190,9 @@

<!-- YAML
changes:
- version: REPLACEME
pr-url: https://github.com/nodejs/node/pull/00000

Check warning on line 4194 in doc/api/deprecations.md

View workflow job for this annotation

GitHub Actions / lint-pr-url

pr-url doesn't match the URL of the current PR.
Comment thread
jasnell marked this conversation as resolved.
Resolved
description: End-of-Life.
- version: v24.0.0
pr-url: https://github.com/nodejs/node/pull/55753
description: Runtime deprecation.
Expand All @@ -4201,10 +4204,10 @@
description: Documentation-only.
-->

Type: Runtime
Type: End-of-Life

Passing non-supported argument types is deprecated and, instead of returning `false`,
will throw an error in a future version.
Passing non-supported argument types to `fs.existsSync()` throws an
`ERR_INVALID_ARG_TYPE` error instead of returning `false`.

### DEP0188: `process.features.ipv6` and `process.features.uv`

Expand Down
7 changes: 6 additions & 1 deletion doc/api/fs.md
Original file line number Diff line number Diff line change
Expand Up @@ -6299,6 +6299,10 @@
<!-- YAML
added: v0.1.21
changes:
- version: REPLACEME
pr-url: https://github.com/nodejs/node/pull/00000

Check warning on line 6303 in doc/api/fs.md

View workflow job for this annotation

GitHub Actions / lint-pr-url

pr-url doesn't match the URL of the current PR.
Comment thread
jasnell marked this conversation as resolved.
Resolved
description: Passing an invalid argument type now throws an
`ERR_INVALID_ARG_TYPE` error instead of returning `false`.
- version: v7.6.0
pr-url: https://github.com/nodejs/node/pull/10739
description: The `path` parameter can be a WHATWG `URL` object using
Expand All @@ -6308,7 +6312,8 @@
* `path` {string|Buffer|URL}
* Returns: {boolean}

Returns `true` if the path exists, `false` otherwise.
Returns `true` if the path exists, `false` otherwise. Throws an
`ERR_INVALID_ARG_TYPE` error if `path` is not a string, {Buffer}, or {URL}.

For detailed information, see the documentation of the asynchronous version of
this API: [`fs.exists()`][].
Expand Down
9 changes: 2 additions & 7 deletions lib/fs.js
Original file line number Diff line number Diff line change
Expand Up @@ -310,11 +310,11 @@ ObjectDefineProperty(exists, kCustomPromisifiedSymbol, {
},
});

let showExistsDeprecation = true;
/**
* Synchronously tests whether or not the given path exists.
* @param {string | Buffer | URL} path
* @returns {boolean}
* @throws {ERR_INVALID_ARG_TYPE} If `path` is not a string, Buffer, or URL.
*/
function existsSync(path) {
const h = vfsState.handlers;
Expand All @@ -325,12 +325,7 @@ function existsSync(path) {
try {
path = getValidatedPath(path);
} catch (err) {
if (showExistsDeprecation && err?.code === 'ERR_INVALID_ARG_TYPE') {
process.emitWarning(
'Passing invalid argument types to fs.existsSync is deprecated', 'DeprecationWarning', 'DEP0187',
);
showExistsDeprecation = false;
}
if (err?.code === 'ERR_INVALID_ARG_TYPE') throw err;
return false;
}

Expand Down
12 changes: 7 additions & 5 deletions test/parallel/test-fs-exists.js
Original file line number Diff line number Diff line change
Expand Up @@ -50,9 +50,11 @@ fs.exists({}, common.mustCall(function(y) {
assert(fs.existsSync(f));
assert(!fs.existsSync(`${f}-NO`));

// fs.existsSync() never throws
const msg = 'Passing invalid argument types to fs.existsSync is deprecated';
common.expectWarning('DeprecationWarning', msg, 'DEP0187');
assert(!fs.existsSync());
assert(!fs.existsSync({}));
// fs.existsSync() throws on invalid argument types
assert.throws(() => fs.existsSync(), { code: 'ERR_INVALID_ARG_TYPE' });
assert.throws(() => fs.existsSync({}), { code: 'ERR_INVALID_ARG_TYPE' });
assert.throws(() => fs.existsSync(123), { code: 'ERR_INVALID_ARG_TYPE' });

// Other invalid paths still return false instead of throwing
assert(!fs.existsSync(new URL('https://foo')));
assert(!fs.existsSync('foo\u0000bar'));
Loading