diff options
author | Ruben Bridgewater <ruben@bridgewater.de> | 2019-04-02 03:46:17 +0200 |
---|---|---|
committer | Ruben Bridgewater <ruben@bridgewater.de> | 2019-04-04 12:51:03 +0200 |
commit | 3b044962c48fe313905877a96b5d0894a5404f6f (patch) | |
tree | f88086693fd685477a88b5cbc5c7442f25a49986 /lib/internal | |
parent | a9bf6652b5353f2098d4c0cd0eb77d17e02e164d (diff) | |
download | android-node-v8-3b044962c48fe313905877a96b5d0894a5404f6f.tar.gz android-node-v8-3b044962c48fe313905877a96b5d0894a5404f6f.tar.bz2 android-node-v8-3b044962c48fe313905877a96b5d0894a5404f6f.zip |
errors: add more information in case of invalid callbacks
This adds the actual callback that is passed through to the error
message in case an ERR_INVALID_CALLBACK error is thrown.
PR-URL: https://github.com/nodejs/node/pull/27048
Reviewed-By: Luigi Pinca <luigipinca@gmail.com>
Reviewed-By: Yongsheng Zhang <zyszys98@gmail.com>
Diffstat (limited to 'lib/internal')
-rw-r--r-- | lib/internal/crypto/keygen.js | 2 | ||||
-rw-r--r-- | lib/internal/crypto/pbkdf2.js | 2 | ||||
-rw-r--r-- | lib/internal/crypto/random.js | 4 | ||||
-rw-r--r-- | lib/internal/crypto/scrypt.js | 2 | ||||
-rw-r--r-- | lib/internal/errors.js | 3 | ||||
-rw-r--r-- | lib/internal/http2/compat.js | 2 | ||||
-rw-r--r-- | lib/internal/http2/core.js | 12 | ||||
-rw-r--r-- | lib/internal/process/task_queues.js | 2 | ||||
-rw-r--r-- | lib/internal/stream_base_commons.js | 4 | ||||
-rw-r--r-- | lib/internal/streams/pipeline.js | 2 | ||||
-rw-r--r-- | lib/internal/timers.js | 2 | ||||
-rw-r--r-- | lib/internal/url.js | 2 |
12 files changed, 20 insertions, 19 deletions
diff --git a/lib/internal/crypto/keygen.js b/lib/internal/crypto/keygen.js index e212f6f451..cff58f15f2 100644 --- a/lib/internal/crypto/keygen.js +++ b/lib/internal/crypto/keygen.js @@ -46,7 +46,7 @@ function generateKeyPair(type, options, callback) { const impl = check(type, options); if (typeof callback !== 'function') - throw new ERR_INVALID_CALLBACK(); + throw new ERR_INVALID_CALLBACK(callback); const wrap = new AsyncWrap(Providers.KEYPAIRGENREQUEST); wrap.ondone = (ex, pubkey, privkey) => { diff --git a/lib/internal/crypto/pbkdf2.js b/lib/internal/crypto/pbkdf2.js index 4694c6ce9a..fc6341b83f 100644 --- a/lib/internal/crypto/pbkdf2.js +++ b/lib/internal/crypto/pbkdf2.js @@ -26,7 +26,7 @@ function pbkdf2(password, salt, iterations, keylen, digest, callback) { check(password, salt, iterations, keylen, digest)); if (typeof callback !== 'function') - throw new ERR_INVALID_CALLBACK(); + throw new ERR_INVALID_CALLBACK(callback); const encoding = getDefaultEncoding(); const keybuf = Buffer.alloc(keylen); diff --git a/lib/internal/crypto/random.js b/lib/internal/crypto/random.js index d26eab7559..257b00a9ce 100644 --- a/lib/internal/crypto/random.js +++ b/lib/internal/crypto/random.js @@ -47,7 +47,7 @@ function assertSize(size, elementSize, offset, length) { function randomBytes(size, cb) { size = assertSize(size, 1, 0, Infinity); if (cb !== undefined && typeof cb !== 'function') - throw new ERR_INVALID_CALLBACK(); + throw new ERR_INVALID_CALLBACK(cb); const buf = Buffer.alloc(size); @@ -95,7 +95,7 @@ function randomFill(buf, offset, size, cb) { cb = size; size = buf.byteLength - offset; } else if (typeof cb !== 'function') { - throw new ERR_INVALID_CALLBACK(); + throw new ERR_INVALID_CALLBACK(cb); } offset = assertOffset(offset, elementSize, buf.byteLength); diff --git a/lib/internal/crypto/scrypt.js b/lib/internal/crypto/scrypt.js index e3cc130c74..0ed4140c9c 100644 --- a/lib/internal/crypto/scrypt.js +++ b/lib/internal/crypto/scrypt.js @@ -32,7 +32,7 @@ function scrypt(password, salt, keylen, options, callback = defaults) { ({ password, salt, keylen } = options); if (typeof callback !== 'function') - throw new ERR_INVALID_CALLBACK(); + throw new ERR_INVALID_CALLBACK(callback); const encoding = getDefaultEncoding(); const keybuf = Buffer.alloc(keylen); diff --git a/lib/internal/errors.js b/lib/internal/errors.js index 3eb387d589..d2bf1999c0 100644 --- a/lib/internal/errors.js +++ b/lib/internal/errors.js @@ -854,7 +854,8 @@ E('ERR_INVALID_ARG_VALUE', (name, value, reason = 'is invalid') => { E('ERR_INVALID_ASYNC_ID', 'Invalid %s value: %s', RangeError); E('ERR_INVALID_BUFFER_SIZE', 'Buffer size must be a multiple of %s', RangeError); -E('ERR_INVALID_CALLBACK', 'Callback must be a function', TypeError); +E('ERR_INVALID_CALLBACK', + 'Callback must be a function. Received %O', TypeError); E('ERR_INVALID_CHAR', // Using a default argument here is important so the argument is not counted // towards `Function#length`. diff --git a/lib/internal/http2/compat.js b/lib/internal/http2/compat.js index 2ba1f49757..ba52c9adea 100644 --- a/lib/internal/http2/compat.js +++ b/lib/internal/http2/compat.js @@ -701,7 +701,7 @@ class Http2ServerResponse extends Stream { createPushResponse(headers, callback) { if (typeof callback !== 'function') - throw new ERR_INVALID_CALLBACK(); + throw new ERR_INVALID_CALLBACK(callback); if (this[kState].closed) { process.nextTick(callback, new ERR_HTTP2_INVALID_STREAM()); return; diff --git a/lib/internal/http2/core.js b/lib/internal/http2/core.js index 51385156d1..2e5db4006f 100644 --- a/lib/internal/http2/core.js +++ b/lib/internal/http2/core.js @@ -1058,7 +1058,7 @@ class Http2Session extends EventEmitter { throw new ERR_HTTP2_PING_LENGTH(); } if (typeof callback !== 'function') - throw new ERR_INVALID_CALLBACK(); + throw new ERR_INVALID_CALLBACK(callback); const cb = pingCallback(callback); if (this.connecting || this.closed) { @@ -1148,7 +1148,7 @@ class Http2Session extends EventEmitter { validateSettings(settings); if (callback && typeof callback !== 'function') - throw new ERR_INVALID_CALLBACK(); + throw new ERR_INVALID_CALLBACK(callback); debug(`Http2Session ${sessionName(this[kType])}: sending settings`); this[kState].pendingAck++; @@ -1900,7 +1900,7 @@ class Http2Stream extends Duplex { if (code < 0 || code > kMaxInt) throw new ERR_OUT_OF_RANGE('code', `>= 0 && <= ${kMaxInt}`, code); if (callback !== undefined && typeof callback !== 'function') - throw new ERR_INVALID_CALLBACK(); + throw new ERR_INVALID_CALLBACK(callback); if (this.closed) return; @@ -2256,7 +2256,7 @@ class ServerHttp2Stream extends Http2Stream { } if (typeof callback !== 'function') - throw new ERR_INVALID_CALLBACK(); + throw new ERR_INVALID_CALLBACK(callback); assertIsObject(options, 'options'); options = { ...options }; @@ -2690,7 +2690,7 @@ class Http2SecureServer extends TLSServer { this.timeout = msecs; if (callback !== undefined) { if (typeof callback !== 'function') - throw new ERR_INVALID_CALLBACK(); + throw new ERR_INVALID_CALLBACK(callback); this.on('timeout', callback); } return this; @@ -2711,7 +2711,7 @@ class Http2Server extends NETServer { this.timeout = msecs; if (callback !== undefined) { if (typeof callback !== 'function') - throw new ERR_INVALID_CALLBACK(); + throw new ERR_INVALID_CALLBACK(callback); this.on('timeout', callback); } return this; diff --git a/lib/internal/process/task_queues.js b/lib/internal/process/task_queues.js index f06a4de535..65ac093802 100644 --- a/lib/internal/process/task_queues.js +++ b/lib/internal/process/task_queues.js @@ -115,7 +115,7 @@ class TickObject { // exit since the callback would not have a chance to be executed. function nextTick(callback) { if (typeof callback !== 'function') - throw new ERR_INVALID_CALLBACK(); + throw new ERR_INVALID_CALLBACK(callback); if (process._exiting) return; diff --git a/lib/internal/stream_base_commons.js b/lib/internal/stream_base_commons.js index 53ddc6336b..0d9d449141 100644 --- a/lib/internal/stream_base_commons.js +++ b/lib/internal/stream_base_commons.js @@ -214,7 +214,7 @@ function setStreamTimeout(msecs, callback) { if (msecs === 0) { if (callback !== undefined) { if (typeof callback !== 'function') - throw new ERR_INVALID_CALLBACK(); + throw new ERR_INVALID_CALLBACK(callback); this.removeListener('timeout', callback); } } else { @@ -223,7 +223,7 @@ function setStreamTimeout(msecs, callback) { if (callback !== undefined) { if (typeof callback !== 'function') - throw new ERR_INVALID_CALLBACK(); + throw new ERR_INVALID_CALLBACK(callback); this.once('timeout', callback); } } diff --git a/lib/internal/streams/pipeline.js b/lib/internal/streams/pipeline.js index bce466db74..798745a110 100644 --- a/lib/internal/streams/pipeline.js +++ b/lib/internal/streams/pipeline.js @@ -58,7 +58,7 @@ function popCallback(streams) { // a single stream. Therefore optimize for the average case instead of // checking for length === 0 as well. if (typeof streams[streams.length - 1] !== 'function') - throw new ERR_INVALID_CALLBACK(); + throw new ERR_INVALID_CALLBACK(streams[streams.length - 1]); return streams.pop(); } diff --git a/lib/internal/timers.js b/lib/internal/timers.js index 239b00129f..0c7388b7bb 100644 --- a/lib/internal/timers.js +++ b/lib/internal/timers.js @@ -351,7 +351,7 @@ function insert(item, refed, start) { function setUnrefTimeout(callback, after) { // Type checking identical to setTimeout() if (typeof callback !== 'function') { - throw new ERR_INVALID_CALLBACK(); + throw new ERR_INVALID_CALLBACK(callback); } const timer = new Timeout(callback, after, undefined, false); diff --git a/lib/internal/url.js b/lib/internal/url.js index 6ef2ad3017..442c164829 100644 --- a/lib/internal/url.js +++ b/lib/internal/url.js @@ -1092,7 +1092,7 @@ defineIDLClass(URLSearchParams.prototype, 'URLSearchParams', { throw new ERR_INVALID_THIS('URLSearchParams'); } if (typeof callback !== 'function') { - throw new ERR_INVALID_CALLBACK(); + throw new ERR_INVALID_CALLBACK(callback); } let list = this[searchParams]; |