mirror of
https://github.com/nodejs/node.git
synced 2024-12-01 16:10:02 +01:00
ac2fc0dd5f
ERR_INVALID_ARG_TYPE is the most common error used throughout the code base. This improves the error message by providing more details to the user and by indicating more precisely which values are allowed ones and which ones are not. It adds the actual input to the error message in case it's a primitive. If it's a class instance, it'll print the class name instead of "object" and "falsy" or similar entries are not named "type" anymore. PR-URL: https://github.com/nodejs/node/pull/29675 Reviewed-By: Rich Trott <rtrott@gmail.com>
79 lines
1.8 KiB
JavaScript
79 lines
1.8 KiB
JavaScript
'use strict';
|
|
|
|
const common = require('../common');
|
|
if (!common.hasCrypto)
|
|
common.skip('missing crypto');
|
|
|
|
const assert = require('assert');
|
|
const http2 = require('http2');
|
|
|
|
// Error if invalid options are passed to createSecureServer.
|
|
const invalidOptions = [() => {}, 1, 'test', null, Symbol('test')];
|
|
invalidOptions.forEach((invalidOption) => {
|
|
assert.throws(
|
|
() => http2.createSecureServer(invalidOption),
|
|
{
|
|
name: 'TypeError',
|
|
code: 'ERR_INVALID_ARG_TYPE',
|
|
message: 'The "options" argument must be of type object.' +
|
|
common.invalidArgTypeHelper(invalidOption)
|
|
}
|
|
);
|
|
});
|
|
|
|
// Error if invalid options.settings are passed to createSecureServer.
|
|
invalidOptions.forEach((invalidSettingsOption) => {
|
|
assert.throws(
|
|
() => http2.createSecureServer({ settings: invalidSettingsOption }),
|
|
{
|
|
name: 'TypeError',
|
|
code: 'ERR_INVALID_ARG_TYPE',
|
|
message: 'The "options.settings" property must be of type object.' +
|
|
common.invalidArgTypeHelper(invalidSettingsOption)
|
|
}
|
|
);
|
|
});
|
|
|
|
// Test that http2.createSecureServer validates input options.
|
|
Object.entries({
|
|
maxSessionInvalidFrames: [
|
|
{
|
|
val: -1,
|
|
err: {
|
|
name: 'RangeError',
|
|
code: 'ERR_OUT_OF_RANGE',
|
|
},
|
|
},
|
|
{
|
|
val: Number.NEGATIVE_INFINITY,
|
|
err: {
|
|
name: 'RangeError',
|
|
code: 'ERR_OUT_OF_RANGE',
|
|
},
|
|
},
|
|
],
|
|
maxSessionRejectedStreams: [
|
|
{
|
|
val: -1,
|
|
err: {
|
|
name: 'RangeError',
|
|
code: 'ERR_OUT_OF_RANGE',
|
|
},
|
|
},
|
|
{
|
|
val: Number.NEGATIVE_INFINITY,
|
|
err: {
|
|
name: 'RangeError',
|
|
code: 'ERR_OUT_OF_RANGE',
|
|
},
|
|
},
|
|
],
|
|
}).forEach(([opt, tests]) => {
|
|
tests.forEach(({ val, err }) => {
|
|
assert.throws(
|
|
() => http2.createSecureServer({ [opt]: val }),
|
|
err
|
|
);
|
|
});
|
|
});
|