Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

buffer: convert buffer.transcode to use internal/errors #16352

Closed
wants to merge 1 commit into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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