diff --git a/lib/_tls_wrap.js b/lib/_tls_wrap.js index e7756f451859dd..f8a9e938c0414d 100644 --- a/lib/_tls_wrap.js +++ b/lib/_tls_wrap.js @@ -633,7 +633,7 @@ TLSSocket.prototype.renegotiate = function(options, callback) { if (options === null || typeof options !== 'object') throw new ERR_INVALID_ARG_TYPE('options', 'Object', options); if (callback !== undefined && typeof callback !== 'function') - throw new ERR_INVALID_CALLBACK(); + throw new ERR_INVALID_CALLBACK(callback); debug('%s renegotiate()', this._tlsOptions.isServer ? 'server' : 'client', diff --git a/lib/dns.js b/lib/dns.js index 3d057d6b50081d..f9c724e7b6d944 100644 --- a/lib/dns.js +++ b/lib/dns.js @@ -98,7 +98,7 @@ function lookup(hostname, options, callback) { callback = options; family = 0; } else if (typeof callback !== 'function') { - throw new ERR_INVALID_CALLBACK(); + throw new ERR_INVALID_CALLBACK(callback); } else if (options !== null && typeof options === 'object') { hints = options.hints >>> 0; family = options.family >>> 0; @@ -174,7 +174,7 @@ function lookupService(hostname, port, callback) { throw new ERR_SOCKET_BAD_PORT(port); if (typeof callback !== 'function') - throw new ERR_INVALID_CALLBACK(); + throw new ERR_INVALID_CALLBACK(callback); port = +port; @@ -213,7 +213,7 @@ function resolver(bindingName) { validateString(name, 'name'); if (typeof callback !== 'function') { - throw new ERR_INVALID_CALLBACK(); + throw new ERR_INVALID_CALLBACK(callback); } const req = new QueryReqWrap(); diff --git a/lib/fs.js b/lib/fs.js index 206ab1fcfe669f..c36eba117489a5 100644 --- a/lib/fs.js +++ b/lib/fs.js @@ -135,7 +135,7 @@ function maybeCallback(cb) { if (typeof cb === 'function') return cb; - throw new ERR_INVALID_CALLBACK(); + throw new ERR_INVALID_CALLBACK(cb); } // Ensure that callbacks run in the global context. Only use this function @@ -143,7 +143,7 @@ function maybeCallback(cb) { // invoked from JS already run in the proper scope. function makeCallback(cb) { if (typeof cb !== 'function') { - throw new ERR_INVALID_CALLBACK(); + throw new ERR_INVALID_CALLBACK(cb); } return (...args) => { @@ -156,7 +156,7 @@ function makeCallback(cb) { // transformed anyway. function makeStatsCallback(cb) { if (typeof cb !== 'function') { - throw new ERR_INVALID_CALLBACK(); + throw new ERR_INVALID_CALLBACK(cb); } return (err, stats) => { @@ -1747,7 +1747,7 @@ function copyFile(src, dest, flags, callback) { callback = flags; flags = 0; } else if (typeof callback !== 'function') { - throw new ERR_INVALID_CALLBACK(); + throw new ERR_INVALID_CALLBACK(callback); } src = toPathIfFileURL(src); diff --git a/lib/inspector.js b/lib/inspector.js index 43cdd53bf0a4b8..c8215ba892fa6b 100644 --- a/lib/inspector.js +++ b/lib/inspector.js @@ -76,7 +76,7 @@ class Session extends EventEmitter { throw new ERR_INVALID_ARG_TYPE('params', 'Object', params); } if (callback && typeof callback !== 'function') { - throw new ERR_INVALID_CALLBACK(); + throw new ERR_INVALID_CALLBACK(callback); } if (!this[connectionSymbol]) { diff --git a/lib/internal/crypto/keygen.js b/lib/internal/crypto/keygen.js index e212f6f4516951..cff58f15f20b4a 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 4694c6ce9a460f..fc6341b83f4110 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 d6b6f47b20ccef..7bbfb91338ebd8 100644 --- a/lib/internal/crypto/random.js +++ b/lib/internal/crypto/random.js @@ -45,7 +45,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); @@ -93,7 +93,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 e3cc130c747592..0ed4140c9c5df5 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 c7dac93783fed3..2b80a81760534f 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 84630a37176e8a..87e4246f08f3f4 100644 --- a/lib/internal/http2/compat.js +++ b/lib/internal/http2/compat.js @@ -699,7 +699,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 3c4e6b55944fde..3a7162447c7c42 100644 --- a/lib/internal/http2/core.js +++ b/lib/internal/http2/core.js @@ -1056,7 +1056,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) { @@ -1146,7 +1146,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++; @@ -1898,7 +1898,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; @@ -2254,7 +2254,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 }; @@ -2688,7 +2688,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; @@ -2709,7 +2709,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 9e4fba6d9df4f0..f6f1d890b47d51 100644 --- a/lib/internal/process/task_queues.js +++ b/lib/internal/process/task_queues.js @@ -113,7 +113,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 53ddc6336b7751..0d9d449141e1fc 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 bce466db749f6c..798745a110d51b 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 9a1b0dea0b0dfb..de4b985371e09f 100644 --- a/lib/internal/timers.js +++ b/lib/internal/timers.js @@ -349,7 +349,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 0771dab13a17a6..11d19640a9a0aa 100644 --- a/lib/internal/url.js +++ b/lib/internal/url.js @@ -1090,7 +1090,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]; diff --git a/lib/perf_hooks.js b/lib/perf_hooks.js index cb92265efc310a..6345bc7a465256 100644 --- a/lib/perf_hooks.js +++ b/lib/perf_hooks.js @@ -283,7 +283,7 @@ let gcTrackingIsEnabled = false; class PerformanceObserver extends AsyncResource { constructor(callback) { if (typeof callback !== 'function') { - throw new ERR_INVALID_CALLBACK(); + throw new ERR_INVALID_CALLBACK(callback); } super('PerformanceObserver'); Object.defineProperties(this, { diff --git a/lib/timers.js b/lib/timers.js index 8dc8b8877bed98..8869e25f53ee5b 100644 --- a/lib/timers.js +++ b/lib/timers.js @@ -120,7 +120,7 @@ function enroll(item, msecs) { function setTimeout(callback, after, arg1, arg2, arg3) { if (typeof callback !== 'function') { - throw new ERR_INVALID_CALLBACK(); + throw new ERR_INVALID_CALLBACK(callback); } var i, args; @@ -166,7 +166,7 @@ function clearTimeout(timer) { function setInterval(callback, repeat, arg1, arg2, arg3) { if (typeof callback !== 'function') { - throw new ERR_INVALID_CALLBACK(); + throw new ERR_INVALID_CALLBACK(callback); } var i, args; @@ -253,7 +253,7 @@ const Immediate = class Immediate { function setImmediate(callback, arg1, arg2, arg3) { if (typeof callback !== 'function') { - throw new ERR_INVALID_CALLBACK(); + throw new ERR_INVALID_CALLBACK(callback); } var i, args; diff --git a/test/parallel/test-crypto-random.js b/test/parallel/test-crypto-random.js index 668607b439a0bd..1d40c8b1814d49 100644 --- a/test/parallel/test-crypto-random.js +++ b/test/parallel/test-crypto-random.js @@ -29,6 +29,7 @@ if (!common.hasCrypto) const assert = require('assert'); const crypto = require('crypto'); const { kMaxLength } = require('buffer'); +const { inspect } = require('util'); const kMaxUint32 = Math.pow(2, 32) - 1; const kMaxPossibleLength = Math.min(kMaxLength, kMaxUint32); @@ -292,7 +293,7 @@ assert.throws( { code: 'ERR_INVALID_CALLBACK', type: TypeError, - message: 'Callback must be a function', + message: `Callback must be a function. Received ${inspect(i)}` }); }); @@ -302,7 +303,7 @@ assert.throws( { code: 'ERR_INVALID_CALLBACK', type: TypeError, - message: 'Callback must be a function', + message: `Callback must be a function. Received ${inspect(i)}` } ); }); diff --git a/test/parallel/test-fs-read.js b/test/parallel/test-fs-read.js index d3de036b67e6e4..9d9cf0db3a7655 100644 --- a/test/parallel/test-fs-read.js +++ b/test/parallel/test-fs-read.js @@ -71,7 +71,7 @@ test(new Uint8Array(expected.length), assert.throws( () => fs.read(fd, Buffer.alloc(1), 0, 1, 0), { - message: 'Callback must be a function', + message: 'Callback must be a function. Received undefined', code: 'ERR_INVALID_CALLBACK', } ); diff --git a/test/parallel/test-http2-client-rststream-before-connect.js b/test/parallel/test-http2-client-rststream-before-connect.js index 8c3eb9bec320d1..d186f418b5b9aa 100644 --- a/test/parallel/test-http2-client-rststream-before-connect.js +++ b/test/parallel/test-http2-client-rststream-before-connect.js @@ -5,6 +5,7 @@ if (!common.hasCrypto) common.skip('missing crypto'); const assert = require('assert'); const h2 = require('http2'); +const { inspect } = require('util'); const server = h2.createServer(); server.on('stream', (stream) => { @@ -35,7 +36,7 @@ server.listen(0, common.mustCall(() => { { type: TypeError, code: 'ERR_INVALID_CALLBACK', - message: 'Callback must be a function' + message: `Callback must be a function. Received ${inspect(notFunction)}` } ); assert.strictEqual(req.closed, false); diff --git a/test/parallel/test-http2-client-settings-before-connect.js b/test/parallel/test-http2-client-settings-before-connect.js index ce888bb4416c09..961292d803ab7a 100644 --- a/test/parallel/test-http2-client-settings-before-connect.js +++ b/test/parallel/test-http2-client-settings-before-connect.js @@ -4,6 +4,7 @@ const common = require('../common'); if (!common.hasCrypto) common.skip('missing crypto'); const h2 = require('http2'); +const { inspect } = require('util'); const server = h2.createServer(); @@ -51,7 +52,8 @@ server.listen(0, common.mustCall(() => { { type: TypeError, code: 'ERR_INVALID_CALLBACK', - message: 'Callback must be a function' + message: + `Callback must be a function. Received ${inspect(invalidCallback)}` } ) ); diff --git a/test/parallel/test-http2-compat-serverresponse-createpushresponse.js b/test/parallel/test-http2-compat-serverresponse-createpushresponse.js index 5790a9942ce680..1ec273a2a137fa 100644 --- a/test/parallel/test-http2-compat-serverresponse-createpushresponse.js +++ b/test/parallel/test-http2-compat-serverresponse-createpushresponse.js @@ -24,7 +24,7 @@ const server = h2.createServer((request, response) => { { code: 'ERR_INVALID_CALLBACK', type: TypeError, - message: 'Callback must be a function' + message: 'Callback must be a function. Received undefined' } ); diff --git a/test/parallel/test-http2-ping.js b/test/parallel/test-http2-ping.js index afb74af827b860..993867bb21c6f2 100644 --- a/test/parallel/test-http2-ping.js +++ b/test/parallel/test-http2-ping.js @@ -7,6 +7,7 @@ if (!common.hasCrypto) const async_hooks = require('async_hooks'); const assert = require('assert'); const http2 = require('http2'); +const { inspect } = require('util'); const pings = new Set(); const events = [0, 0, 0, 0]; @@ -119,7 +120,8 @@ server.listen(0, common.mustCall(() => { { type: TypeError, code: 'ERR_INVALID_CALLBACK', - message: 'Callback must be a function' + message: 'Callback must be a function. ' + + `Received ${inspect(invalidCallback)}` } ) ); diff --git a/test/parallel/test-http2-server-push-stream-errors-args.js b/test/parallel/test-http2-server-push-stream-errors-args.js index 0c3b9dcfccda8d..c9f9291c4d1d9f 100644 --- a/test/parallel/test-http2-server-push-stream-errors-args.js +++ b/test/parallel/test-http2-server-push-stream-errors-args.js @@ -22,7 +22,7 @@ server.on('stream', common.mustCall((stream, headers) => { }, {}, 'callback'), { code: 'ERR_INVALID_CALLBACK', - message: 'Callback must be a function' + message: "Callback must be a function. Received 'callback'" } ); diff --git a/test/parallel/test-http2-server-settimeout-no-callback.js b/test/parallel/test-http2-server-settimeout-no-callback.js index a43fbb212958c8..5dff0fa8e7a93b 100644 --- a/test/parallel/test-http2-server-settimeout-no-callback.js +++ b/test/parallel/test-http2-server-settimeout-no-callback.js @@ -6,23 +6,23 @@ if (!common.hasCrypto) const assert = require('assert'); const http2 = require('http2'); +const { inspect } = require('util'); // Verify that setTimeout callback verifications work correctly const verifyCallbacks = (server) => { const testTimeout = 10; - const notFunctions = [true, 1, {}, [], null, 'test']; - const invalidCallBackError = { - type: TypeError, - code: 'ERR_INVALID_CALLBACK', - message: 'Callback must be a function' - }; - notFunctions.forEach((notFunction) => + [true, 1, {}, [], null, 'test'].forEach((notFunction) => { common.expectsError( () => server.setTimeout(testTimeout, notFunction), - invalidCallBackError - ) - ); + { + type: TypeError, + code: 'ERR_INVALID_CALLBACK', + message: 'Callback must be a function. ' + + `Received ${inspect(notFunction)}` + } + ); + }); // No callback const returnedVal = server.setTimeout(testTimeout); diff --git a/test/parallel/test-http2-timeouts.js b/test/parallel/test-http2-timeouts.js index 3a75d63580e1cc..323e6bdd24e48a 100644 --- a/test/parallel/test-http2-timeouts.js +++ b/test/parallel/test-http2-timeouts.js @@ -29,7 +29,7 @@ server.on('stream', common.mustCall((stream) => { { code: 'ERR_INVALID_CALLBACK', type: TypeError, - message: 'Callback must be a function' + message: 'Callback must be a function. Received Symbol(test)' } ); common.expectsError( @@ -37,7 +37,7 @@ server.on('stream', common.mustCall((stream) => { { code: 'ERR_INVALID_CALLBACK', type: TypeError, - message: 'Callback must be a function' + message: 'Callback must be a function. Received {}' } ); })); diff --git a/test/parallel/test-net-socket-timeout.js b/test/parallel/test-net-socket-timeout.js index f0f5f194bf304c..2fe0e5a45d7372 100644 --- a/test/parallel/test-net-socket-timeout.js +++ b/test/parallel/test-net-socket-timeout.js @@ -23,6 +23,7 @@ const common = require('../common'); const net = require('net'); const assert = require('assert'); +const { inspect } = require('util'); // Verify that invalid delays throw const s = new net.Socket(); @@ -59,7 +60,8 @@ for (let i = 0; i < invalidCallbacks.length; i++) { { code: 'ERR_INVALID_CALLBACK', type: TypeError, - message: 'Callback must be a function' + message: 'Callback must be a function. ' + + `Received ${inspect(invalidCallbacks[i])}` } ) ); diff --git a/test/parallel/test-performanceobserver.js b/test/parallel/test-performanceobserver.js index 06c1281666bfd5..513d7db220c0d1 100644 --- a/test/parallel/test-performanceobserver.js +++ b/test/parallel/test-performanceobserver.js @@ -4,6 +4,7 @@ const common = require('../common'); const Countdown = require('../common/countdown'); const assert = require('assert'); +const { inspect } = require('util'); const { internalBinding } = require('internal/test/binding'); const { observerCounts: counts @@ -30,12 +31,14 @@ assert.strictEqual(counts[NODE_PERFORMANCE_ENTRY_TYPE_FUNCTION], 0); { [1, null, undefined, {}, [], Infinity].forEach((i) => { - common.expectsError(() => new PerformanceObserver(i), - { - code: 'ERR_INVALID_CALLBACK', - type: TypeError, - message: 'Callback must be a function' - }); + common.expectsError( + () => new PerformanceObserver(i), + { + code: 'ERR_INVALID_CALLBACK', + type: TypeError, + message: `Callback must be a function. Received ${inspect(i)}` + } + ); }); const observer = new PerformanceObserver(common.mustNotCall()); diff --git a/test/parallel/test-process-next-tick.js b/test/parallel/test-process-next-tick.js index 59de0da42d3962..6641e17c242437 100644 --- a/test/parallel/test-process-next-tick.js +++ b/test/parallel/test-process-next-tick.js @@ -21,6 +21,7 @@ 'use strict'; const common = require('../common'); +const { inspect } = require('util'); const N = 2; function cb() { @@ -38,10 +39,12 @@ process.on('exit', function() { }); [null, 1, 'test', {}, [], Infinity, true].forEach((i) => { - common.expectsError(() => process.nextTick(i), - { - code: 'ERR_INVALID_CALLBACK', - type: TypeError, - message: 'Callback must be a function' - }); + common.expectsError( + () => process.nextTick(i), + { + code: 'ERR_INVALID_CALLBACK', + type: TypeError, + message: `Callback must be a function. Received ${inspect(i)}` + } + ); }); diff --git a/test/parallel/test-timers-refresh.js b/test/parallel/test-timers-refresh.js index 597d5c9241947a..28267f2b7b50b9 100644 --- a/test/parallel/test-timers-refresh.js +++ b/test/parallel/test-timers-refresh.js @@ -6,6 +6,7 @@ const common = require('../common'); const { strictEqual } = require('assert'); const { setUnrefTimeout } = require('internal/timers'); +const { inspect } = require('util'); // Schedule the unrefed cases first so that the later case keeps the event loop // active. @@ -32,14 +33,14 @@ const { setUnrefTimeout } = require('internal/timers'); // Should throw with non-functions { - const expectedError = { - code: 'ERR_INVALID_CALLBACK', - message: 'Callback must be a function' - }; - [null, true, false, 0, 1, NaN, '', 'foo', {}, Symbol()].forEach((cb) => { - common.expectsError(() => setUnrefTimeout(cb), - expectedError); + common.expectsError( + () => setUnrefTimeout(cb), + { + code: 'ERR_INVALID_CALLBACK', + message: `Callback must be a function. Received ${inspect(cb)}` + } + ); }); } diff --git a/test/sequential/test-inspector-module.js b/test/sequential/test-inspector-module.js index 26bb7fe9262889..010f03c6e43e83 100644 --- a/test/sequential/test-inspector-module.js +++ b/test/sequential/test-inspector-module.js @@ -5,6 +5,7 @@ const common = require('../common'); common.skipIfInspectorDisabled(); const { Session } = require('inspector'); +const { inspect } = require('util'); const session = new Session(); @@ -52,7 +53,7 @@ session.post('Runtime.evaluate', { expression: '2 + 2' }); { code: 'ERR_INVALID_CALLBACK', type: TypeError, - message: 'Callback must be a function' + message: `Callback must be a function. Received ${inspect(i)}` } ); });