Skip to content

Commit 0117db7

Browse files
committed
buffer: convert buffer.transcode to use internal/errors
`buffer.transcode` is still using raw TypeError. This change is to convert it to use internal/errors. Ref: nodejs#11273
1 parent 1395106 commit 0117db7

File tree

2 files changed

+9
-3
lines changed

2 files changed

+9
-3
lines changed

lib/buffer.js

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1562,7 +1562,8 @@ if (process.binding('config').hasIntl) {
15621562
// Buffer instance.
15631563
transcode = function transcode(source, fromEncoding, toEncoding) {
15641564
if (!isUint8Array(source))
1565-
throw new TypeError('"source" argument must be a Buffer or Uint8Array');
1565+
throw new errors.TypeError('ERR_INVALID_ARG_TYPE', 'source',
1566+
['Buffer', 'Uint8Array'], source);
15661567
if (source.length === 0) return Buffer.alloc(0);
15671568

15681569
fromEncoding = normalizeEncoding(fromEncoding) || fromEncoding;

test/parallel/test-icu-transcode.js

Lines changed: 7 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -41,9 +41,14 @@ for (const test in tests) {
4141
utf8_to_ucs2.toString('ucs2'));
4242
}
4343

44-
assert.throws(
44+
common.expectsError(
4545
() => buffer.transcode(null, 'utf8', 'ascii'),
46-
/^TypeError: "source" argument must be a Buffer or Uint8Array$/
46+
{
47+
type: TypeError,
48+
code: 'ERR_INVALID_ARG_TYPE',
49+
message: 'The "source" argument must be one of type Buffer ' +
50+
'or Uint8Array. Received type null'
51+
}
4752
);
4853

4954
assert.throws(

0 commit comments

Comments
 (0)