]> zoso.dev Git - buffer.git/commitdiff
Fix error message from new Buffer(num) (test-buffer-new.js)
authorFeross Aboukhadijeh <feross@feross.org>
Fri, 16 Feb 2018 08:14:25 +0000 (00:14 -0800)
committerFeross Aboukhadijeh <feross@feross.org>
Fri, 16 Feb 2018 08:14:25 +0000 (00:14 -0800)
index.js
test/node/test-buffer-new.js [new file with mode: 0644]

index 2dfbefe0e74484f479bfc6c5a309fd741a1c3e54..1c783effba0fd01a112b8d60fdf1e41cbcd02e1c 100644 (file)
--- 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 (file)
index 0000000..3869280
--- /dev/null
@@ -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'
+});
+