Skip to content

Commit

Permalink
fixup! fs: deprecate never throw behaviour in fs.existsSync
Browse files Browse the repository at this point in the history
  • Loading branch information
Ceres6 committed Jan 6, 2025
1 parent 83687f4 commit 0484b00
Show file tree
Hide file tree
Showing 2 changed files with 8 additions and 8 deletions.
14 changes: 6 additions & 8 deletions lib/fs.js
Original file line number Diff line number Diff line change
Expand Up @@ -273,11 +273,7 @@ ObjectDefineProperty(exists, kCustomPromisifiedSymbol, {
},
});

// fs.existsSync never throws, it only returns true or false.
// Since fs.existsSync never throws, users have established
// the expectation that passing invalid arguments to it, even like
// fs.existsSync(), would only get a false in return, so we cannot signal
// validation errors to users properly out of compatibility concerns.
let showExistsDeprecation = true;
/**
* Synchronously tests whether or not the given path exists.
* @param {string | Buffer | URL} path
Expand All @@ -287,9 +283,11 @@ function existsSync(path) {
try {
path = getValidatedPath(path);
} catch {
if (!deprecationWarningEmitted) {
process.emitWarning('Passing invalid argument types to fs.existsSync is deprecated', 'DeprecationWarning', 'DEP0187');
deprecationWarningEmitted = true;
if (showExistsDeprecation) {
process.emitWarning(
'Passing invalid argument types to fs.existsSync is deprecated', 'DeprecationWarning', 'DEP0187',
);
showExistsDeprecation = false;
}
return false;
}
Expand Down
2 changes: 2 additions & 0 deletions test/parallel/test-fs-exists.js
Original file line number Diff line number Diff line change
Expand Up @@ -51,6 +51,8 @@ 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({}));
assert(!fs.existsSync(new URL('https://foo')));

0 comments on commit 0484b00

Please sign in to comment.