Permalink
Browse files

buffer: buffer.transcode to use internal/errors

`buffer.transcode` is still using raw TypeError. This change is to
convert it to use internal/errors.

Ref: #11273
PR-URL: #16352
Reviewed-By: James M Snell <jasnell@gmail.com>
Reviewed-By: Luigi Pinca <luigipinca@gmail.com>
Reviewed-By: Michaël Zasso <targos@protonmail.com>
Reviewed-By: Joyee Cheung <joyeec9h3@gmail.com>
Reviewed-By: Gireesh Punathil <gpunathi@in.ibm.com>
  • Loading branch information...
starkwang authored and gireeshpunathil committed Oct 21, 2017
1 parent f1d6b04 commit e79a61cf80335498c3150dafd9036de8ec6b9914
Showing with 9 additions and 3 deletions.
  1. +2 −1 lib/buffer.js
  2. +7 −2 test/parallel/test-icu-transcode.js
View
@@ -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;
@@ -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(

0 comments on commit e79a61c

Please sign in to comment.