aboutsummaryrefslogtreecommitdiff
path: root/lib/internal/http2/core.js
diff options
context:
space:
mode:
authorRuben Bridgewater <ruben@bridgewater.de>2018-03-19 13:33:46 +0100
committerRuben Bridgewater <ruben@bridgewater.de>2018-03-25 01:45:37 +0100
commitc6b6c92185316e13738e6fa931fdd5303e381e46 (patch)
treec38af9cd1a0a8cd6eeb459af3adee4dfd390fdc6 /lib/internal/http2/core.js
parenteeb57022e6bada13955a19b15232a9ee4fe9b465 (diff)
downloadandroid-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/internal/http2/core.js')
-rw-r--r--lib/internal/http2/core.js24
1 files changed, 14 insertions, 10 deletions
diff --git a/lib/internal/http2/core.js b/lib/internal/http2/core.js
index 9978df87d6..89cc8db0b0 100644
--- a/lib/internal/http2/core.js
+++ b/lib/internal/http2/core.js
@@ -984,7 +984,7 @@ class Http2Session extends EventEmitter {
throw new ERR_HTTP2_INVALID_SESSION();
if (typeof id !== 'number')
- throw new ERR_INVALID_ARG_TYPE('id', 'number');
+ throw new ERR_INVALID_ARG_TYPE('id', 'number', id);
if (id <= 0 || id > kMaxStreams)
throw new ERR_OUT_OF_RANGE('id', `> 0 and <= ${kMaxStreams}`, id);
this[kHandle].setNextStreamID(id);
@@ -1003,7 +1003,8 @@ class Http2Session extends EventEmitter {
}
if (payload && !isArrayBufferView(payload)) {
throw new ERR_INVALID_ARG_TYPE('payload',
- ['Buffer', 'TypedArray', 'DataView']);
+ ['Buffer', 'TypedArray', 'DataView'],
+ payload);
}
if (payload && payload.length !== 8) {
throw new ERR_HTTP2_PING_LENGTH();
@@ -1122,13 +1123,14 @@ class Http2Session extends EventEmitter {
if (opaqueData !== undefined && !isArrayBufferView(opaqueData)) {
throw new ERR_INVALID_ARG_TYPE('opaqueData',
- ['Buffer', 'TypedArray', 'DataView']);
+ ['Buffer', 'TypedArray', 'DataView'],
+ opaqueData);
}
if (typeof code !== 'number') {
- throw new ERR_INVALID_ARG_TYPE('code', 'number');
+ throw new ERR_INVALID_ARG_TYPE('code', 'number', code);
}
if (typeof lastStreamID !== 'number') {
- throw new ERR_INVALID_ARG_TYPE('lastStreamID', 'number');
+ throw new ERR_INVALID_ARG_TYPE('lastStreamID', 'number', lastStreamID);
}
const goawayFn = submitGoaway.bind(this, code, lastStreamID, opaqueData);
@@ -1321,14 +1323,15 @@ class ServerHttp2Session extends Http2Session {
// be invalid.
if (typeof origin !== 'string') {
throw new ERR_INVALID_ARG_TYPE('originOrStream',
- ['string', 'number', 'URL', 'object']);
+ ['string', 'number', 'URL', 'object'],
+ originOrStream);
} else if (origin === 'null' || origin.length === 0) {
throw new ERR_HTTP2_ALTSVC_INVALID_ORIGIN();
}
}
if (typeof alt !== 'string')
- throw new ERR_INVALID_ARG_TYPE('alt', 'string');
+ throw new ERR_INVALID_ARG_TYPE('alt', 'string', alt);
if (!kQuotedString.test(alt))
throw new ERR_INVALID_CHAR('alt');
@@ -1794,7 +1797,7 @@ class Http2Stream extends Duplex {
// but no DATA and HEADERS frames may be sent.
close(code = NGHTTP2_NO_ERROR, callback) {
if (typeof code !== 'number')
- throw new ERR_INVALID_ARG_TYPE('code', 'number');
+ throw new ERR_INVALID_ARG_TYPE('code', 'number', code);
if (code < 0 || code > kMaxInt)
throw new ERR_OUT_OF_RANGE('code');
if (callback !== undefined && typeof callback !== 'function')
@@ -2313,7 +2316,7 @@ class ServerHttp2Stream extends Http2Stream {
}
if (typeof fd !== 'number')
- throw new ERR_INVALID_ARG_TYPE('fd', 'number');
+ throw new ERR_INVALID_ARG_TYPE('fd', 'number', fd);
debug(`Http2Stream ${this[kID]} [Http2Session ` +
`${sessionName(session[kType])}]: initiating response from fd`);
@@ -2767,7 +2770,8 @@ function getPackedSettings(settings) {
function getUnpackedSettings(buf, options = {}) {
if (!isArrayBufferView(buf)) {
- throw new ERR_INVALID_ARG_TYPE('buf', ['Buffer', 'TypedArray', 'DataView']);
+ throw new ERR_INVALID_ARG_TYPE('buf',
+ ['Buffer', 'TypedArray', 'DataView'], buf);
}
if (buf.length % 6 !== 0)
throw new ERR_HTTP2_INVALID_PACKED_SETTINGS_LENGTH();