Skip to content

Commit 5c1b27f

Browse files
committed
http2: validate settings input
The settings input was not marked as optional in our documentation but we did not throw an error in those cases. The API does not seem to be useful without the correct input, so I went for throwing an error in such cases instead of updating the documentation.
1 parent 4b70d2d commit 5c1b27f

File tree

2 files changed

+9
-3
lines changed

2 files changed

+9
-3
lines changed

lib/internal/http2/core.js

+5-1
Original file line numberDiff line numberDiff line change
@@ -789,7 +789,11 @@ function pingCallback(cb) {
789789
// 6. enablePush must be a boolean
790790
// All settings are optional and may be left undefined
791791
function validateSettings(settings) {
792-
if (settings === undefined) return;
792+
if (settings === undefined) {
793+
const err = new ERR_INVALID_ARG_TYPE('settings', 'object', settings);
794+
Error.captureStackTrace(err, 'validateSettings');
795+
throw err;
796+
}
793797
assertWithinRange('headerTableSize',
794798
settings.headerTableSize,
795799
0, kMaxInt);

test/parallel/test-http2-getpackedsettings.js

+4-2
Original file line numberDiff line numberDiff line change
@@ -88,8 +88,10 @@ http2.getPackedSettings({ enablePush: false });
8888

8989
// Check for not passing settings.
9090
{
91-
const packed = http2.getPackedSettings();
92-
assert.strictEqual(packed.length, 0);
91+
assert.throws(
92+
() => http2.getPackedSettings(),
93+
{ code: 'ERR_INVALID_ARG_TYPE' }
94+
);
9395
}
9496

9597
{

0 commit comments

Comments
 (0)