From: Feross Aboukhadijeh Date: Fri, 16 Feb 2018 08:14:25 +0000 (-0800) Subject: Fix error message from new Buffer(num) (test-buffer-new.js) X-Git-Url: https://zoso.dev/?a=commitdiff_plain;h=229a7038da2a6f80fa446b86541adb3a30308e05;p=buffer.git Fix error message from new Buffer(num) (test-buffer-new.js) --- diff --git a/index.js b/index.js index 2dfbefe..1c783ef 100644 --- a/index.js +++ b/index.js @@ -91,8 +91,8 @@ function Buffer (arg, encodingOrOffset, length) { // Common case. if (typeof arg === 'number') { if (typeof encodingOrOffset === 'string') { - throw new Error( - 'If encoding is specified then the first argument must be a string' + throw new TypeError( + 'The "string" argument must be of type string. Received type number' ) } return allocUnsafe(arg) diff --git a/test/node/test-buffer-new.js b/test/node/test-buffer-new.js new file mode 100644 index 0000000..3869280 --- /dev/null +++ b/test/node/test-buffer-new.js @@ -0,0 +1,11 @@ +'use strict'; +var Buffer = require('../../').Buffer; + +const common = require('./common'); + +common.expectsError(() => new Buffer(42, 'utf8'), { + code: 'ERR_INVALID_ARG_TYPE', + type: TypeError, + message: 'The "string" argument must be of type string. Received type number' +}); +