From 81fabe26bb04f12e2acd4da37b2c3b9bc9a69b6d Mon Sep 17 00:00:00 2001 From: Ruben Bridgewater Date: Thu, 26 Apr 2018 02:13:39 +0200 Subject: [PATCH 1/2] http2: fix ping callback In case there was no ack, the callback would have returned more than the error as return value. This makes sure that is not the case anymore. --- lib/internal/http2/core.js | 7 +++++-- 1 file changed, 5 insertions(+), 2 deletions(-) diff --git a/lib/internal/http2/core.js b/lib/internal/http2/core.js index 495fa60ba39ce3..61e32483a143ea 100644 --- a/lib/internal/http2/core.js +++ b/lib/internal/http2/core.js @@ -716,8 +716,11 @@ const proxySocketHandler = { // data received on the PING acknowlegement. function pingCallback(cb) { return function pingCallback(ack, duration, payload) { - const err = ack ? null : new ERR_HTTP2_PING_CANCEL(); - cb(err, duration, payload); + if (ack) { + cb(null, duration, payload); + } else { + cb(new ERR_HTTP2_PING_CANCEL()); + } }; } From 6202d98657f119cf1c8c1947786c11154ad04b70 Mon Sep 17 00:00:00 2001 From: Ruben Bridgewater Date: Thu, 26 Apr 2018 02:14:25 +0200 Subject: [PATCH 2/2] test: verify arguments length in common.expectsError If `common.expectsError` is used as a callback, it will now also verify that there is only one argument (the expected error). --- test/common/index.js | 5 +++++ 1 file changed, 5 insertions(+) diff --git a/test/common/index.js b/test/common/index.js index 95bb8dd804881f..bbd2b62d7da768 100644 --- a/test/common/index.js +++ b/test/common/index.js @@ -708,6 +708,11 @@ exports.expectsError = function expectsError(fn, settings, exact) { } function innerFn(error) { + if (arguments.length !== 1) { + // Do not use `assert.strictEqual()` to prevent `util.inspect` from + // always being called. + assert.fail(`Expected one argument, got ${util.inspect(arguments)}`); + } const descriptor = Object.getOwnPropertyDescriptor(error, 'message'); assert.strictEqual(descriptor.enumerable, false, 'The error message should be non-enumerable');