Skip to content

Commit

Permalink
buffer: convert buffer.transcode to use internal/errors
Browse files Browse the repository at this point in the history
`buffer.transcode` is still using raw TypeError. This change is to
convert it to use internal/errors.

Ref: nodejs#11273
  • Loading branch information
starkwang committed Oct 22, 2017
1 parent 1395106 commit 0117db7
Show file tree
Hide file tree
Showing 2 changed files with 9 additions and 3 deletions.
3 changes: 2 additions & 1 deletion lib/buffer.js
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down
9 changes: 7 additions & 2 deletions test/parallel/test-icu-transcode.js
Original file line number Diff line number Diff line change
Expand Up @@ -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(
Expand Down

0 comments on commit 0117db7

Please sign in to comment.