http2: refer to stream errors by name

Display the constant name instead of a stream error code
in the error message, because the numerical codes give absolutely
no clue about what happened when an error is emitted.

PR-URL: https://github.com/nodejs/node/pull/18966
Reviewed-By: James M Snell <jasnell@gmail.com>
Reviewed-By: Minwoo Jung <minwoo@nodesource.com>
Reviewed-By: Joyee Cheung <joyeec9h3@gmail.com>
Reviewed-By: Colin Ihrig <cjihrig@gmail.com>
Reviewed-By: Ruben Bridgewater <ruben@bridgewater.de>
Reviewed-By: Tobias Nießen <tniessen@tnie.de>
This commit is contained in:
Anna Henningsen 2018-02-23 22:28:29 +01:00 committed by Anatoli Papirovski
parent f2b9805f85
commit 7bc8eb8da7
No known key found for this signature in database
GPG Key ID: 614E2E1ABEB4B2C0
19 changed files with 58 additions and 43 deletions

View File

@ -63,7 +63,7 @@ const {
} = require('internal/timers');
const { ShutdownWrap, WriteWrap } = process.binding('stream_wrap');
const { constants } = binding;
const { constants, nameForErrorCode } = binding;
const NETServer = net.Server;
const TLSServer = tls.Server;
@ -1849,7 +1849,8 @@ class Http2Stream extends Duplex {
// abort and is already covered by aborted event, also allows more
// seamless compatibility with http1
if (err == null && code !== NGHTTP2_NO_ERROR && code !== NGHTTP2_CANCEL)
err = new errors.Error('ERR_HTTP2_STREAM_ERROR', code);
err = new errors.Error('ERR_HTTP2_STREAM_ERROR',
nameForErrorCode[code] || code);
this[kSession] = undefined;
this[kHandle] = undefined;

View File

@ -2929,29 +2929,39 @@ void Initialize(Local<Object> target,
session->GetFunction()).FromJust();
Local<Object> constants = Object::New(isolate);
NODE_DEFINE_CONSTANT(constants, NGHTTP2_SESSION_SERVER);
NODE_DEFINE_CONSTANT(constants, NGHTTP2_SESSION_CLIENT);
NODE_DEFINE_CONSTANT(constants, NGHTTP2_STREAM_STATE_IDLE);
NODE_DEFINE_CONSTANT(constants, NGHTTP2_STREAM_STATE_OPEN);
NODE_DEFINE_CONSTANT(constants, NGHTTP2_STREAM_STATE_RESERVED_LOCAL);
NODE_DEFINE_CONSTANT(constants, NGHTTP2_STREAM_STATE_RESERVED_REMOTE);
NODE_DEFINE_CONSTANT(constants, NGHTTP2_STREAM_STATE_HALF_CLOSED_LOCAL);
NODE_DEFINE_CONSTANT(constants, NGHTTP2_STREAM_STATE_HALF_CLOSED_REMOTE);
NODE_DEFINE_CONSTANT(constants, NGHTTP2_STREAM_STATE_CLOSED);
NODE_DEFINE_CONSTANT(constants, NGHTTP2_NO_ERROR);
NODE_DEFINE_CONSTANT(constants, NGHTTP2_PROTOCOL_ERROR);
NODE_DEFINE_CONSTANT(constants, NGHTTP2_INTERNAL_ERROR);
NODE_DEFINE_CONSTANT(constants, NGHTTP2_FLOW_CONTROL_ERROR);
NODE_DEFINE_CONSTANT(constants, NGHTTP2_SETTINGS_TIMEOUT);
NODE_DEFINE_CONSTANT(constants, NGHTTP2_STREAM_CLOSED);
NODE_DEFINE_CONSTANT(constants, NGHTTP2_FRAME_SIZE_ERROR);
NODE_DEFINE_CONSTANT(constants, NGHTTP2_REFUSED_STREAM);
NODE_DEFINE_CONSTANT(constants, NGHTTP2_CANCEL);
NODE_DEFINE_CONSTANT(constants, NGHTTP2_COMPRESSION_ERROR);
NODE_DEFINE_CONSTANT(constants, NGHTTP2_CONNECT_ERROR);
NODE_DEFINE_CONSTANT(constants, NGHTTP2_ENHANCE_YOUR_CALM);
NODE_DEFINE_CONSTANT(constants, NGHTTP2_INADEQUATE_SECURITY);
NODE_DEFINE_CONSTANT(constants, NGHTTP2_HTTP_1_1_REQUIRED);
Local<Array> name_for_error_code = Array::New(isolate);
#define NODE_NGHTTP2_ERROR_CODES(V) \
V(NGHTTP2_SESSION_SERVER); \
V(NGHTTP2_SESSION_CLIENT); \
V(NGHTTP2_STREAM_STATE_IDLE); \
V(NGHTTP2_STREAM_STATE_OPEN); \
V(NGHTTP2_STREAM_STATE_RESERVED_LOCAL); \
V(NGHTTP2_STREAM_STATE_RESERVED_REMOTE); \
V(NGHTTP2_STREAM_STATE_HALF_CLOSED_LOCAL); \
V(NGHTTP2_STREAM_STATE_HALF_CLOSED_REMOTE); \
V(NGHTTP2_STREAM_STATE_CLOSED); \
V(NGHTTP2_NO_ERROR); \
V(NGHTTP2_PROTOCOL_ERROR); \
V(NGHTTP2_INTERNAL_ERROR); \
V(NGHTTP2_FLOW_CONTROL_ERROR); \
V(NGHTTP2_SETTINGS_TIMEOUT); \
V(NGHTTP2_STREAM_CLOSED); \
V(NGHTTP2_FRAME_SIZE_ERROR); \
V(NGHTTP2_REFUSED_STREAM); \
V(NGHTTP2_CANCEL); \
V(NGHTTP2_COMPRESSION_ERROR); \
V(NGHTTP2_CONNECT_ERROR); \
V(NGHTTP2_ENHANCE_YOUR_CALM); \
V(NGHTTP2_INADEQUATE_SECURITY); \
V(NGHTTP2_HTTP_1_1_REQUIRED); \
#define V(name) \
NODE_DEFINE_CONSTANT(constants, name); \
name_for_error_code->Set(static_cast<int>(name), \
FIXED_ONE_BYTE_STRING(isolate, #name));
NODE_NGHTTP2_ERROR_CODES(V)
#undef V
NODE_DEFINE_HIDDEN_CONSTANT(constants, NGHTTP2_HCAT_REQUEST);
NODE_DEFINE_HIDDEN_CONSTANT(constants, NGHTTP2_HCAT_RESPONSE);
@ -3016,6 +3026,9 @@ HTTP_STATUS_CODES(V)
target->Set(context,
FIXED_ONE_BYTE_STRING(isolate, "constants"),
constants).FromJust();
target->Set(context,
FIXED_ONE_BYTE_STRING(isolate, "nameForErrorCode"),
name_for_error_code).FromJust();
}
} // namespace http2
} // namespace node

View File

@ -59,7 +59,7 @@ server.listen(0, common.mustCall(() => {
req.on('error', common.expectsError({
code: 'ERR_HTTP2_STREAM_ERROR',
type: Error,
message: `Stream closed with error code ${closeCode}`
message: 'Stream closed with error code NGHTTP2_PROTOCOL_ERROR'
}));
req.on('response', common.mustCall());

View File

@ -18,7 +18,8 @@ server.on('stream', (stream) => {
// system specific timings.
stream.on('error', (err) => {
assert.strictEqual(err.code, 'ERR_HTTP2_STREAM_ERROR');
assert.strictEqual(err.message, 'Stream closed with error code 2');
assert.strictEqual(err.message,
'Stream closed with error code NGHTTP2_INTERNAL_ERROR');
});
stream.respond();
stream.end();

View File

@ -27,7 +27,7 @@ server.listen(0, common.mustCall(() => {
req.on('error', common.expectsError({
code: 'ERR_HTTP2_STREAM_ERROR',
type: Error,
message: 'Stream closed with error code 1'
message: 'Stream closed with error code NGHTTP2_PROTOCOL_ERROR'
}));
req.on('close', common.mustCall(() => countdown.dec()));
}

View File

@ -58,7 +58,7 @@ server.listen(0, common.mustCall(() => {
req.on('error', common.expectsError({
code: 'ERR_HTTP2_STREAM_ERROR',
type: Error,
message: 'Stream closed with error code 2'
message: 'Stream closed with error code NGHTTP2_INTERNAL_ERROR'
}));
req.on('close', common.mustCall(() => countdown.dec()));
@ -73,7 +73,7 @@ server.listen(0, common.mustCall(() => {
req.on('error', common.expectsError({
code: 'ERR_HTTP2_STREAM_ERROR',
type: Error,
message: 'Stream closed with error code 2'
message: 'Stream closed with error code NGHTTP2_INTERNAL_ERROR'
}));
req.on('close', common.mustCall(() => countdown.dec()));

View File

@ -72,7 +72,7 @@ function runTest(test) {
req.on('error', common.expectsError({
code: 'ERR_HTTP2_STREAM_ERROR',
type: Error,
message: 'Stream closed with error code 2'
message: 'Stream closed with error code NGHTTP2_INTERNAL_ERROR'
}));
req.on('close', common.mustCall(() => {

View File

@ -50,7 +50,7 @@ server.listen(0, common.mustCall(() => {
req.on('error', common.expectsError({
code: 'ERR_HTTP2_STREAM_ERROR',
type: Error,
message: 'Stream closed with error code 7'
message: 'Stream closed with error code NGHTTP2_REFUSED_STREAM'
}));
}
}));

View File

@ -63,7 +63,7 @@ server.on('stream', (stream) => {
stream.on('error', common.expectsError({
code: 'ERR_HTTP2_STREAM_ERROR',
type: Error,
message: 'Stream closed with error code 3'
message: 'Stream closed with error code NGHTTP2_FLOW_CONTROL_ERROR'
}));
stream.on('close', common.mustCall(() => {
server.close();

View File

@ -69,7 +69,7 @@ server.on('stream', (stream) => {
stream.on('error', common.expectsError({
code: 'ERR_HTTP2_STREAM_ERROR',
type: Error,
message: 'Stream closed with error code 3'
message: 'Stream closed with error code NGHTTP2_FLOW_CONTROL_ERROR'
}));
stream.on('close', common.mustCall(() => {
server.close(common.mustCall());

View File

@ -41,7 +41,7 @@ server.listen(0, common.mustCall(() => {
req.on('error', common.expectsError({
code: 'ERR_HTTP2_STREAM_ERROR',
type: Error,
message: 'Stream closed with error code 2'
message: 'Stream closed with error code NGHTTP2_INTERNAL_ERROR'
}));
req.on('response', common.mustCall());

View File

@ -58,7 +58,7 @@ server.listen(0, common.mustCall(() => {
req.on('error', common.expectsError({
code: 'ERR_HTTP2_STREAM_ERROR',
type: Error,
message: 'Stream closed with error code 1'
message: 'Stream closed with error code NGHTTP2_PROTOCOL_ERROR'
}));
}
}));

View File

@ -38,6 +38,6 @@ server.listen(0, common.mustCall(() => {
req.on('error', common.expectsError({
code: 'ERR_HTTP2_STREAM_ERROR',
type: Error,
message: 'Stream closed with error code 7'
message: 'Stream closed with error code NGHTTP2_REFUSED_STREAM'
}));
}));

View File

@ -15,7 +15,7 @@ const {
const errorCheck = common.expectsError({
code: 'ERR_HTTP2_STREAM_ERROR',
type: Error,
message: `Stream closed with error code ${NGHTTP2_INTERNAL_ERROR}`
message: 'Stream closed with error code NGHTTP2_INTERNAL_ERROR'
}, 2);
const server = http2.createServer();

View File

@ -80,7 +80,7 @@ function runTest(test) {
req.on('error', common.expectsError({
code: 'ERR_HTTP2_STREAM_ERROR',
type: Error,
message: 'Stream closed with error code 2'
message: 'Stream closed with error code NGHTTP2_INTERNAL_ERROR'
}));
currentError = test;

View File

@ -88,7 +88,7 @@ function runTest(test) {
req.on('error', common.expectsError({
code: 'ERR_HTTP2_STREAM_ERROR',
type: Error,
message: 'Stream closed with error code 2'
message: 'Stream closed with error code NGHTTP2_INTERNAL_ERROR'
}));
currentError = test;

View File

@ -20,7 +20,7 @@ server.listen(0, common.mustCall(() => {
req.on('error', common.expectsError({
code: 'ERR_HTTP2_STREAM_ERROR',
type: Error,
message: 'Stream closed with error code 11'
message: 'Stream closed with error code NGHTTP2_ENHANCE_YOUR_CALM'
}));
req.on('close', common.mustCall((code) => {
assert.strictEqual(code, NGHTTP2_ENHANCE_YOUR_CALM);

View File

@ -23,7 +23,7 @@ server.listen(0, common.mustCall(() => {
req.on('error', common.expectsError({
code: 'ERR_HTTP2_STREAM_ERROR',
type: Error,
message: 'Stream closed with error code 11'
message: 'Stream closed with error code NGHTTP2_ENHANCE_YOUR_CALM'
}));
req.on('close', common.mustCall((code) => {
assert.strictEqual(code, NGHTTP2_ENHANCE_YOUR_CALM);

View File

@ -30,7 +30,7 @@ server.listen(0, common.mustCall(() => {
req.on('error', common.expectsError({
code: 'ERR_HTTP2_STREAM_ERROR',
type: Error,
message: 'Stream closed with error code 11'
message: 'Stream closed with error code NGHTTP2_ENHANCE_YOUR_CALM'
}));
req.on('close', common.mustCall(() => {
server.close();