diff --git a/lib/internal/errors.js b/lib/internal/errors.js index 7c4728627731fe..bcb4635d7d88a6 100644 --- a/lib/internal/errors.js +++ b/lib/internal/errors.js @@ -1404,7 +1404,8 @@ E('ERR_INVALID_ARG_TYPE', // For cases like 'first argument' msg += `${name} `; } else { - const type = StringPrototypeIncludes(name, '.') ? 'property' : 'argument'; + const type = (StringPrototypeIncludes(name, '.') || + StringPrototypeIncludes(name, '[')) ? 'property' : 'argument'; msg += `"${name}" ${type} `; } msg += 'must be '; @@ -1468,7 +1469,8 @@ E('ERR_INVALID_ARG_VALUE', (name, value, reason = 'is invalid') => { if (inspected.length > 128) { inspected = `${StringPrototypeSlice(inspected, 0, 128)}...`; } - const type = StringPrototypeIncludes(name, '.') ? 'property' : 'argument'; + const type = (StringPrototypeIncludes(name, '.') || + StringPrototypeIncludes(name, '[')) ? 'property' : 'argument'; return `The ${type} '${name}' ${reason}. Received ${inspected}`; }, TypeError, RangeError, HideStackFramesError); E('ERR_INVALID_ASYNC_ID', 'Invalid %s value: %s', RangeError); diff --git a/test/parallel/test-buffer-concat.js b/test/parallel/test-buffer-concat.js index 39e6ca7997ecba..32c81ebcd8dc56 100644 --- a/test/parallel/test-buffer-concat.js +++ b/test/parallel/test-buffer-concat.js @@ -59,7 +59,7 @@ assert.strictEqual(flatLongLen.toString(), check); Buffer.concat(value); }, { code: 'ERR_INVALID_ARG_TYPE', - message: 'The "list[0]" argument must be an instance of Buffer ' + + message: 'The "list[0]" property must be an instance of Buffer ' + `or Uint8Array.${common.invalidArgTypeHelper(value[0])}` }); }); @@ -68,7 +68,7 @@ assert.throws(() => { Buffer.concat([Buffer.from('hello'), 3]); }, { code: 'ERR_INVALID_ARG_TYPE', - message: 'The "list[1]" argument must be an instance of Buffer ' + + message: 'The "list[1]" property must be an instance of Buffer ' + 'or Uint8Array. Received type number (3)' }); diff --git a/test/parallel/test-diff.js b/test/parallel/test-diff.js index dfc7027a3ed909..00a0e2b0b15d5d 100644 --- a/test/parallel/test-diff.js +++ b/test/parallel/test-diff.js @@ -31,7 +31,7 @@ describe('diff', () => { const expected = ['1', '2']; assert.throws(() => diff(actual, expected), { - message: 'The "actual[1]" argument must be of type string. Received an instance of Object' + message: 'The "actual[1]" property must be of type string. Received an instance of Object' }); }); diff --git a/test/parallel/test-dns-setservers-type-check.js b/test/parallel/test-dns-setservers-type-check.js index 007cae4f95d681..7daf02139e19c0 100644 --- a/test/parallel/test-dns-setservers-type-check.js +++ b/test/parallel/test-dns-setservers-type-check.js @@ -60,7 +60,7 @@ const promiseResolver = new dns.promises.Resolver(); const errObj = { code: 'ERR_INVALID_ARG_TYPE', name: 'TypeError', - message: 'The "servers[0]" argument must be of type string.' + + message: 'The "servers[0]" property must be of type string.' + common.invalidArgTypeHelper(val[0]) }; assert.throws( @@ -110,7 +110,7 @@ const promiseResolver = new dns.promises.Resolver(); const errObj = { code: 'ERR_INVALID_ARG_TYPE', name: 'TypeError', - message: 'The "servers[0]" argument must be of type string.' + + message: 'The "servers[0]" property must be of type string.' + common.invalidArgTypeHelper(val[0]) }; assert.throws(() => { diff --git a/test/parallel/test-process-setgroups.js b/test/parallel/test-process-setgroups.js index 49d147b6c2ddf5..b440b16a2b5650 100644 --- a/test/parallel/test-process-setgroups.js +++ b/test/parallel/test-process-setgroups.js @@ -42,7 +42,7 @@ assert.throws( { code: 'ERR_INVALID_ARG_TYPE', name: 'TypeError', - message: 'The "groups[0]" argument must be ' + + message: 'The "groups[0]" property must be ' + 'one of type number or string.' + common.invalidArgTypeHelper(val) } diff --git a/test/parallel/test-tls-set-default-ca-certificates-error.js b/test/parallel/test-tls-set-default-ca-certificates-error.js index 1d529a97265a14..f1a7ef08de88a8 100644 --- a/test/parallel/test-tls-set-default-ca-certificates-error.js +++ b/test/parallel/test-tls-set-default-ca-certificates-error.js @@ -27,14 +27,14 @@ for (const invalid of [null, undefined, 42, {}, true]) { // Test input validation - should throw when passed an array with invalid elements assert.throws(() => tls.setDefaultCACertificates([invalid]), { code: 'ERR_INVALID_ARG_TYPE', - message: /The "certs\[0\]" argument must be of type string or an instance of ArrayBufferView/ + message: /The "certs\[0\]" property must be of type string or an instance of ArrayBufferView/ }); // Verify that default certificates remain unchanged after error. assertEqualCerts(tls.getCACertificates('default'), defaultCerts); assert.throws(() => tls.setDefaultCACertificates([fixtureCert, invalid]), { code: 'ERR_INVALID_ARG_TYPE', - message: /The "certs\[1\]" argument must be of type string or an instance of ArrayBufferView/ + message: /The "certs\[1\]" property must be of type string or an instance of ArrayBufferView/ }); // Verify that default certificates remain unchanged after error. assertEqualCerts(tls.getCACertificates('default'), defaultCerts);