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
Expand file treeCollapse file tree
Open diff view settings
Collapse file
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 number | Diff line number | Diff line change |
|---|
@@ -3779,14 +3779,17 @@ It is recommended to use the `new` qualifier instead. This applies to all REPL c |
3779 | 3779 |
|
3780 | 3780 | <!-- YAML |
3781 | 3781 | changes: |
| 3782 | + - version: REPLACEME |
| 3783 | + pr-url: https://github.com/nodejs/node/pull/55753 |
| 3784 | + description: Runtime deprecation. |
3782 | 3785 | - version: |
3783 | 3786 | - v23.4.0 |
3784 | 3787 | - v22.13.0 |
3785 | 3788 | pr-url: https://github.com/nodejs/node/pull/55892 |
3786 | 3789 | description: Documentation-only. |
3787 | 3790 | --> |
3788 | 3791 |
|
3789 | | -Type: Documentation-only |
| 3792 | +Type: Runtime |
3790 | 3793 |
|
3791 | 3794 | Passing non-supported argument types is deprecated and, instead of returning `false`, |
3792 | 3795 | will throw an error in a future version. |
|
Collapse file
Copy file name to clipboardExpand all lines: lib/fs.js +7-6Lines changed: 7 additions & 6 deletions | Original file line number | Diff line number | Diff line change |
|---|
@@ -273,12 +273,7 @@ ObjectDefineProperty(exists, kCustomPromisifiedSymbol, { |
273 | 273 | }, |
274 | 274 | }); |
275 | 275 |
|
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; |
282 | 277 | /** |
283 | 278 | * Synchronously tests whether or not the given path exists. |
284 | 279 | * @param {string | Buffer | URL} path |
@@ -288,6 +283,12 @@ function existsSync(path) { |
288 | 283 | try { |
289 | 284 | path = getValidatedPath(path); |
290 | 285 | } catch { |
| 286 | + if (showExistsDeprecation) { |
| 287 | + process.emitWarning( |
| 288 | + 'Passing invalid argument types to fs.existsSync is deprecated', 'DeprecationWarning', 'DEP0187', |
| 289 | + ); |
| 290 | + showExistsDeprecation = false; |
| 291 | + } |
291 | 292 | return false; |
292 | 293 | } |
293 | 294 |
|
|
Collapse file
Copy file name to clipboardExpand all lines: test/parallel/test-fs-exists.js +2Lines changed: 2 additions & 0 deletions | Original file line number | Diff line number | Diff line change |
|---|
@@ -51,6 +51,8 @@ assert(fs.existsSync(f)); |
51 | 51 | assert(!fs.existsSync(`${f}-NO`)); |
52 | 52 |
|
53 | 53 | // fs.existsSync() never throws |
| 54 | +const msg = 'Passing invalid argument types to fs.existsSync is deprecated'; |
| 55 | +common.expectWarning('DeprecationWarning', msg, 'DEP0187'); |
54 | 56 | assert(!fs.existsSync()); |
55 | 57 | assert(!fs.existsSync({})); |
56 | 58 | assert(!fs.existsSync(new URL('https://foo'))); |