diff --git a/lib/buffer.js b/lib/buffer.js index 6a176756c01bfa..908e8b56e8182c 100644 --- a/lib/buffer.js +++ b/lib/buffer.js @@ -1562,7 +1562,8 @@ if (process.binding('config').hasIntl) { // Buffer instance. transcode = function transcode(source, fromEncoding, toEncoding) { if (!isUint8Array(source)) - throw new TypeError('"source" argument must be a Buffer or Uint8Array'); + throw new errors.TypeError('ERR_INVALID_ARG_TYPE', 'source', + ['Buffer', 'Uint8Array'], source); if (source.length === 0) return Buffer.alloc(0); fromEncoding = normalizeEncoding(fromEncoding) || fromEncoding; diff --git a/test/parallel/test-icu-transcode.js b/test/parallel/test-icu-transcode.js index ad2c7ff273eefd..4f51e7230452ce 100644 --- a/test/parallel/test-icu-transcode.js +++ b/test/parallel/test-icu-transcode.js @@ -41,9 +41,14 @@ for (const test in tests) { utf8_to_ucs2.toString('ucs2')); } -assert.throws( +common.expectsError( () => buffer.transcode(null, 'utf8', 'ascii'), - /^TypeError: "source" argument must be a Buffer or Uint8Array$/ + { + type: TypeError, + code: 'ERR_INVALID_ARG_TYPE', + message: 'The "source" argument must be one of type Buffer ' + + 'or Uint8Array. Received type null' + } ); assert.throws(