diff options
author | Ruben Bridgewater <ruben@bridgewater.de> | 2018-03-19 13:33:46 +0100 |
---|---|---|
committer | Ruben Bridgewater <ruben@bridgewater.de> | 2018-03-25 01:45:37 +0100 |
commit | c6b6c92185316e13738e6fa931fdd5303e381e46 (patch) | |
tree | c38af9cd1a0a8cd6eeb459af3adee4dfd390fdc6 /lib/util.js | |
parent | eeb57022e6bada13955a19b15232a9ee4fe9b465 (diff) | |
download | android-node-v8-c6b6c92185316e13738e6fa931fdd5303e381e46.tar.gz android-node-v8-c6b6c92185316e13738e6fa931fdd5303e381e46.tar.bz2 android-node-v8-c6b6c92185316e13738e6fa931fdd5303e381e46.zip |
lib: always show ERR_INVALID_ARG_TYPE received part
This makes a effort to make sure all of these errors will actually
also show the received input.
On top of that it refactors a few tests for better maintainability.
It will also change the returned type to always be a simple typeof
instead of special handling null.
PR-URL: https://github.com/nodejs/node/pull/19445
Reviewed-By: James M Snell <jasnell@gmail.com>
Reviewed-By: Matteo Collina <matteo.collina@gmail.com>
Reviewed-By: Joyee Cheung <joyeec9h3@gmail.com>
Reviewed-By: Anna Henningsen <anna@addaleax.net>
Diffstat (limited to 'lib/util.js')
-rw-r--r-- | lib/util.js | 13 |
1 files changed, 7 insertions, 6 deletions
diff --git a/lib/util.js b/lib/util.js index eabdf6c1df..2cf79bb5f0 100644 --- a/lib/util.js +++ b/lib/util.js @@ -323,7 +323,7 @@ Object.defineProperty(inspect, 'defaultOptions', { }, set(options) { if (options === null || typeof options !== 'object') { - throw new ERR_INVALID_ARG_TYPE('options', 'Object'); + throw new ERR_INVALID_ARG_TYPE('options', 'Object', options); } return _extend(inspectDefaultOptions, options); } @@ -1024,13 +1024,14 @@ function log() { function inherits(ctor, superCtor) { if (ctor === undefined || ctor === null) - throw new ERR_INVALID_ARG_TYPE('ctor', 'Function'); + throw new ERR_INVALID_ARG_TYPE('ctor', 'Function', ctor); if (superCtor === undefined || superCtor === null) - throw new ERR_INVALID_ARG_TYPE('superCtor', 'Function'); + throw new ERR_INVALID_ARG_TYPE('superCtor', 'Function', superCtor); if (superCtor.prototype === undefined) { - throw new ERR_INVALID_ARG_TYPE('superCtor.prototype', 'Function'); + throw new ERR_INVALID_ARG_TYPE('superCtor.prototype', + 'Function', superCtor.prototype); } ctor.super_ = superCtor; Object.setPrototypeOf(ctor.prototype, superCtor.prototype); @@ -1088,7 +1089,7 @@ function callbackifyOnRejected(reason, cb) { function callbackify(original) { if (typeof original !== 'function') { - throw new ERR_INVALID_ARG_TYPE('original', 'Function'); + throw new ERR_INVALID_ARG_TYPE('original', 'Function', original); } // We DO NOT return the promise as it gives the user a false sense that @@ -1097,7 +1098,7 @@ function callbackify(original) { function callbackified(...args) { const maybeCb = args.pop(); if (typeof maybeCb !== 'function') { - throw new ERR_INVALID_ARG_TYPE('last argument', 'Function'); + throw new ERR_INVALID_ARG_TYPE('last argument', 'Function', maybeCb); } const cb = (...args) => { Reflect.apply(maybeCb, this, args); }; // In true node style we process the callback on `nextTick` with all the |