errors: improve ERR_INVALID_ARG_TYPE

ERR_INVALID_ARG_TYPE is the most common error used throughout the
code base. This improves the error message by providing more details
to the user and by indicating more precisely which values are allowed
ones and which ones are not.

It adds the actual input to the error message in case it's a primitive.
If it's a class instance, it'll print the class name instead of
"object" and "falsy" or similar entries are not named "type" anymore.

PR-URL: https://github.com/nodejs/node/pull/29675
Reviewed-By: Rich Trott <rtrott@gmail.com>
This commit is contained in:
Ruben Bridgewater authored and Beth Griggs committed 2020-02-06 02:49:32 +00:00
1 parent ae3459af9f
commit df94cfb67c
127 files changed
+666 -538

No files matched your search

+3 -2
View File
@@ -43,8 +43,9 @@ assert.throws(function() {
}, {
code: 'ERR_INVALID_ARG_TYPE',
name: 'TypeError',
message: 'The first argument must be one of type string, Buffer,' +
' ArrayBuffer, Array, or Array-like Object. Received type object'
message: 'The first argument must be of type string or an instance of ' +
'Buffer, ArrayBuffer, or Array or an Array-like Object. Received ' +
'an instance of AB'
});
// Test the byteOffset and length arguments