Skip to content

Commit e08d7d4

Browse files
jasnelltargos
authored andcommitted
lib: fixup incorrect argument order in assertEncoding
PR-URL: #57177 Reviewed-By: Yagiz Nizipli <yagiz@nizipli.com> Reviewed-By: Colin Ihrig <cjihrig@gmail.com> Reviewed-By: Antoine du Hamel <duhamelantoine1995@gmail.com> Reviewed-By: Chemi Atlow <chemi@atlow.co.il> Reviewed-By: Luigi Pinca <luigipinca@gmail.com>
1 parent 455bf5a commit e08d7d4

File tree

2 files changed

+16
-1
lines changed

2 files changed

+16
-1
lines changed

lib/internal/fs/utils.js

+1-1
Original file line numberDiff line numberDiff line change
@@ -154,7 +154,7 @@ function lazyLoadFs() {
154154
function assertEncoding(encoding) {
155155
if (encoding && !Buffer.isEncoding(encoding)) {
156156
const reason = 'is invalid encoding';
157-
throw new ERR_INVALID_ARG_VALUE(encoding, 'encoding', reason);
157+
throw new ERR_INVALID_ARG_VALUE('encoding', encoding, reason);
158158
}
159159
}
160160

Original file line numberDiff line numberDiff line change
@@ -0,0 +1,15 @@
1+
'use strict';
2+
3+
// Tests to verify that a correctly formatted invalid encoding error
4+
// is thrown. Originally the internal assertEncoding utility was
5+
// reversing the arguments when constructing the ERR_INVALID_ARG_VALUE
6+
// error.
7+
8+
require('../common');
9+
const { opendirSync } = require('node:fs');
10+
const { throws } = require('node:assert');
11+
12+
throws(() => opendirSync('.', { encoding: 'no' }), {
13+
code: 'ERR_INVALID_ARG_VALUE',
14+
message: 'The argument \'encoding\' is invalid encoding. Received \'no\'',
15+
});

0 commit comments

Comments
 (0)