From e08d7d4e5366dd0ef2bee70f43f9027c2144441a Mon Sep 17 00:00:00 2001 From: James M Snell Date: Sat, 22 Feb 2025 15:07:27 -0800 Subject: [PATCH] lib: fixup incorrect argument order in assertEncoding PR-URL: https://github.com/nodejs/node/pull/57177 Reviewed-By: Yagiz Nizipli Reviewed-By: Colin Ihrig Reviewed-By: Antoine du Hamel Reviewed-By: Chemi Atlow Reviewed-By: Luigi Pinca --- lib/internal/fs/utils.js | 2 +- test/parallel/test-fs-internal-assertencoding.js | 15 +++++++++++++++ 2 files changed, 16 insertions(+), 1 deletion(-) create mode 100644 test/parallel/test-fs-internal-assertencoding.js diff --git a/lib/internal/fs/utils.js b/lib/internal/fs/utils.js index d54ab2112461aa..8d7f32a8925cc8 100644 --- a/lib/internal/fs/utils.js +++ b/lib/internal/fs/utils.js @@ -154,7 +154,7 @@ function lazyLoadFs() { function assertEncoding(encoding) { if (encoding && !Buffer.isEncoding(encoding)) { const reason = 'is invalid encoding'; - throw new ERR_INVALID_ARG_VALUE(encoding, 'encoding', reason); + throw new ERR_INVALID_ARG_VALUE('encoding', encoding, reason); } } diff --git a/test/parallel/test-fs-internal-assertencoding.js b/test/parallel/test-fs-internal-assertencoding.js new file mode 100644 index 00000000000000..ea88517b908861 --- /dev/null +++ b/test/parallel/test-fs-internal-assertencoding.js @@ -0,0 +1,15 @@ +'use strict'; + +// Tests to verify that a correctly formatted invalid encoding error +// is thrown. Originally the internal assertEncoding utility was +// reversing the arguments when constructing the ERR_INVALID_ARG_VALUE +// error. + +require('../common'); +const { opendirSync } = require('node:fs'); +const { throws } = require('node:assert'); + +throws(() => opendirSync('.', { encoding: 'no' }), { + code: 'ERR_INVALID_ARG_VALUE', + message: 'The argument \'encoding\' is invalid encoding. Received \'no\'', +});