Skip to content

Commit 3a5b9f5

Browse files
committed
errors: fix incorrect argument label for array elements
1 parent f6464c5 commit 3a5b9f5

File tree

6 files changed

+12
-10
lines changed

6 files changed

+12
-10
lines changed

lib/internal/errors.js

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1404,7 +1404,8 @@ E('ERR_INVALID_ARG_TYPE',
14041404
// For cases like 'first argument'
14051405
msg += `${name} `;
14061406
} else {
1407-
const type = StringPrototypeIncludes(name, '.') ? 'property' : 'argument';
1407+
const type = (StringPrototypeIncludes(name, '.') ||
1408+
StringPrototypeIncludes(name, '[')) ? 'property' : 'argument';
14081409
msg += `"${name}" ${type} `;
14091410
}
14101411
msg += 'must be ';
@@ -1468,7 +1469,8 @@ E('ERR_INVALID_ARG_VALUE', (name, value, reason = 'is invalid') => {
14681469
if (inspected.length > 128) {
14691470
inspected = `${StringPrototypeSlice(inspected, 0, 128)}...`;
14701471
}
1471-
const type = StringPrototypeIncludes(name, '.') ? 'property' : 'argument';
1472+
const type = (StringPrototypeIncludes(name, '.') ||
1473+
StringPrototypeIncludes(name, '[')) ? 'property' : 'argument';
14721474
return `The ${type} '${name}' ${reason}. Received ${inspected}`;
14731475
}, TypeError, RangeError, HideStackFramesError);
14741476
E('ERR_INVALID_ASYNC_ID', 'Invalid %s value: %s', RangeError);

test/parallel/test-buffer-concat.js

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -59,7 +59,7 @@ assert.strictEqual(flatLongLen.toString(), check);
5959
Buffer.concat(value);
6060
}, {
6161
code: 'ERR_INVALID_ARG_TYPE',
62-
message: 'The "list[0]" argument must be an instance of Buffer ' +
62+
message: 'The "list[0]" property must be an instance of Buffer ' +
6363
`or Uint8Array.${common.invalidArgTypeHelper(value[0])}`
6464
});
6565
});
@@ -68,7 +68,7 @@ assert.throws(() => {
6868
Buffer.concat([Buffer.from('hello'), 3]);
6969
}, {
7070
code: 'ERR_INVALID_ARG_TYPE',
71-
message: 'The "list[1]" argument must be an instance of Buffer ' +
71+
message: 'The "list[1]" property must be an instance of Buffer ' +
7272
'or Uint8Array. Received type number (3)'
7373
});
7474

test/parallel/test-diff.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -31,7 +31,7 @@ describe('diff', () => {
3131
const expected = ['1', '2'];
3232

3333
assert.throws(() => diff(actual, expected), {
34-
message: 'The "actual[1]" argument must be of type string. Received an instance of Object'
34+
message: 'The "actual[1]" property must be of type string. Received an instance of Object'
3535
});
3636
});
3737

test/parallel/test-dns-setservers-type-check.js

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -60,7 +60,7 @@ const promiseResolver = new dns.promises.Resolver();
6060
const errObj = {
6161
code: 'ERR_INVALID_ARG_TYPE',
6262
name: 'TypeError',
63-
message: 'The "servers[0]" argument must be of type string.' +
63+
message: 'The "servers[0]" property must be of type string.' +
6464
common.invalidArgTypeHelper(val[0])
6565
};
6666
assert.throws(
@@ -110,7 +110,7 @@ const promiseResolver = new dns.promises.Resolver();
110110
const errObj = {
111111
code: 'ERR_INVALID_ARG_TYPE',
112112
name: 'TypeError',
113-
message: 'The "servers[0]" argument must be of type string.' +
113+
message: 'The "servers[0]" property must be of type string.' +
114114
common.invalidArgTypeHelper(val[0])
115115
};
116116
assert.throws(() => {

test/parallel/test-process-setgroups.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -42,7 +42,7 @@ assert.throws(
4242
{
4343
code: 'ERR_INVALID_ARG_TYPE',
4444
name: 'TypeError',
45-
message: 'The "groups[0]" argument must be ' +
45+
message: 'The "groups[0]" property must be ' +
4646
'one of type number or string.' +
4747
common.invalidArgTypeHelper(val)
4848
}

test/parallel/test-tls-set-default-ca-certificates-error.js

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -27,14 +27,14 @@ for (const invalid of [null, undefined, 42, {}, true]) {
2727
// Test input validation - should throw when passed an array with invalid elements
2828
assert.throws(() => tls.setDefaultCACertificates([invalid]), {
2929
code: 'ERR_INVALID_ARG_TYPE',
30-
message: /The "certs\[0\]" argument must be of type string or an instance of ArrayBufferView/
30+
message: /The "certs\[0\]" property must be of type string or an instance of ArrayBufferView/
3131
});
3232
// Verify that default certificates remain unchanged after error.
3333
assertEqualCerts(tls.getCACertificates('default'), defaultCerts);
3434

3535
assert.throws(() => tls.setDefaultCACertificates([fixtureCert, invalid]), {
3636
code: 'ERR_INVALID_ARG_TYPE',
37-
message: /The "certs\[1\]" argument must be of type string or an instance of ArrayBufferView/
37+
message: /The "certs\[1\]" property must be of type string or an instance of ArrayBufferView/
3838
});
3939
// Verify that default certificates remain unchanged after error.
4040
assertEqualCerts(tls.getCACertificates('default'), defaultCerts);

0 commit comments

Comments
 (0)