From 0484b00374b10a34d531d055352812402333997c Mon Sep 17 00:00:00 2001 From: Carlos Espa Date: Wed, 27 Nov 2024 19:17:06 +0100 Subject: [PATCH] fixup! fs: deprecate never throw behaviour in fs.existsSync --- lib/fs.js | 14 ++++++-------- test/parallel/test-fs-exists.js | 2 ++ 2 files changed, 8 insertions(+), 8 deletions(-) diff --git a/lib/fs.js b/lib/fs.js index 332298d4bcabd0..e2996ba9ca4ef6 100644 --- a/lib/fs.js +++ b/lib/fs.js @@ -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 @@ -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; } diff --git a/test/parallel/test-fs-exists.js b/test/parallel/test-fs-exists.js index 857f3f26174549..3be2197660ce8c 100644 --- a/test/parallel/test-fs-exists.js +++ b/test/parallel/test-fs-exists.js @@ -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')));