GV

GeezerVison

The World Wide Web, restored to 800 pixels of glory.

Home|About|Gaming cabinet|Archives|How it works|Starter sites

On this site

  • Sign in
  • ActionsCI/CD and automation
  • CodespacesCloud development environments
  • All Features
  • Documentation
  • Training
  • Certifications
  • Build with Copilot
  • Customize Copilot
  • Integrations
  • Trending repos
  • GitHub Sponsors
  • Developer articles
  • Enterprises

This view

  • Original page
  • New address

GeezerVison is showing github.com — fs: deprecate passing invalid types in `fs.existsSync` · nodejs/node@529b56e

File tree

Expand file treeCollapse file tree
Open diff view settings
Filter options
  • doc/api
    • deprecations.md
  • lib
    • fs.js
  • test/parallel
    • test-fs-exists.js
Expand file treeCollapse file tree
Open diff view settings
Collapse file

‎doc/api/deprecations.md‎

Copy file name to clipboardExpand all lines: doc/api/deprecations.md
+4-1Lines changed: 4 additions & 1 deletion
  • Display the source diff
  • Display the rich diff
Original file line numberDiff line numberDiff line change
@@ -3779,14 +3779,17 @@ It is recommended to use the `new` qualifier instead. This applies to all REPL c
37793779

37803780
<!-- YAML
37813781
changes:
3782+
- version: REPLACEME
3783+
pr-url: https://github.com/nodejs/node/pull/55753
3784+
description: Runtime deprecation.
37823785
- version:
37833786
- v23.4.0
37843787
- v22.13.0
37853788
pr-url: https://github.com/nodejs/node/pull/55892
37863789
description: Documentation-only.
37873790
-->
37883791

3789-
Type: Documentation-only
3792+
Type: Runtime
37903793

37913794
Passing non-supported argument types is deprecated and, instead of returning `false`,
37923795
will throw an error in a future version.
Collapse file

‎lib/fs.js‎

Copy file name to clipboardExpand all lines: lib/fs.js
+7-6Lines changed: 7 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -273,12 +273,7 @@ ObjectDefineProperty(exists, kCustomPromisifiedSymbol, {
273273
},
274274
});
275275

276-
// fs.existsSync never throws, it only returns true or false.
277-
// Since fs.existsSync never throws, users have established
278-
// the expectation that passing invalid arguments to it, even like
279-
// fs.existsSync(), would only get a false in return, so we cannot signal
280-
// validation errors to users properly out of compatibility concerns.
281-
// TODO(joyeecheung): deprecate the never-throw-on-invalid-arguments behavior
276+
let showExistsDeprecation = true;
282277
/**
283278
* Synchronously tests whether or not the given path exists.
284279
* @param {string | Buffer | URL} path
@@ -288,6 +283,12 @@ function existsSync(path) {
288283
try {
289284
path = getValidatedPath(path);
290285
} catch {
286+
if (showExistsDeprecation) {
287+
process.emitWarning(
288+
'Passing invalid argument types to fs.existsSync is deprecated', 'DeprecationWarning', 'DEP0187',
289+
);
290+
showExistsDeprecation = false;
291+
}
291292
return false;
292293
}
293294

Collapse file

‎test/parallel/test-fs-exists.js‎

Copy file name to clipboardExpand all lines: test/parallel/test-fs-exists.js
+2Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -51,6 +51,8 @@ assert(fs.existsSync(f));
5151
assert(!fs.existsSync(`${f}-NO`));
5252

5353
// fs.existsSync() never throws
54+
const msg = 'Passing invalid argument types to fs.existsSync is deprecated';
55+
common.expectWarning('DeprecationWarning', msg, 'DEP0187');
5456
assert(!fs.existsSync());
5557
assert(!fs.existsSync({}));
5658
assert(!fs.existsSync(new URL('https://foo')));

0 commit comments

Comments
0 (0)
You are visitor 01402503 — GeezerVison does not store the pages you look up.
Best viewed with Netscape Navigator 4.7 or Internet Explorer 6 at 800×600. No cookies required.