Skip to content
This repository has been archived by the owner on Aug 31, 2018. It is now read-only.

Commit

Permalink
buffer: 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/node#11273
PR-URL: nodejs/node#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 addaleax committed Oct 26, 2017
1 parent acaf4bf commit 2603b69
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 2603b69

Please sign in to comment.