Skip to content

Commit 7bc8eb8

Browse files
addaleaxapapirovski
authored andcommitted
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: #18966 Reviewed-By: James M Snell <[email protected]> Reviewed-By: Minwoo Jung <[email protected]> Reviewed-By: Joyee Cheung <[email protected]> Reviewed-By: Colin Ihrig <[email protected]> Reviewed-By: Ruben Bridgewater <[email protected]> Reviewed-By: Tobias Nießen <[email protected]>
1 parent f2b9805 commit 7bc8eb8

19 files changed

+58
-43
lines changed

lib/internal/http2/core.js

+3-2
Original file line numberDiff line numberDiff line change
@@ -63,7 +63,7 @@ const {
6363
} = require('internal/timers');
6464

6565
const { ShutdownWrap, WriteWrap } = process.binding('stream_wrap');
66-
const { constants } = binding;
66+
const { constants, nameForErrorCode } = binding;
6767

6868
const NETServer = net.Server;
6969
const TLSServer = tls.Server;
@@ -1849,7 +1849,8 @@ class Http2Stream extends Duplex {
18491849
// abort and is already covered by aborted event, also allows more
18501850
// seamless compatibility with http1
18511851
if (err == null && code !== NGHTTP2_NO_ERROR && code !== NGHTTP2_CANCEL)
1852-
err = new errors.Error('ERR_HTTP2_STREAM_ERROR', code);
1852+
err = new errors.Error('ERR_HTTP2_STREAM_ERROR',
1853+
nameForErrorCode[code] || code);
18531854

18541855
this[kSession] = undefined;
18551856
this[kHandle] = undefined;

src/node_http2.cc

+36-23
Original file line numberDiff line numberDiff line change
@@ -2929,29 +2929,39 @@ void Initialize(Local<Object> target,
29292929
session->GetFunction()).FromJust();
29302930

29312931
Local<Object> constants = Object::New(isolate);
2932-
NODE_DEFINE_CONSTANT(constants, NGHTTP2_SESSION_SERVER);
2933-
NODE_DEFINE_CONSTANT(constants, NGHTTP2_SESSION_CLIENT);
2934-
NODE_DEFINE_CONSTANT(constants, NGHTTP2_STREAM_STATE_IDLE);
2935-
NODE_DEFINE_CONSTANT(constants, NGHTTP2_STREAM_STATE_OPEN);
2936-
NODE_DEFINE_CONSTANT(constants, NGHTTP2_STREAM_STATE_RESERVED_LOCAL);
2937-
NODE_DEFINE_CONSTANT(constants, NGHTTP2_STREAM_STATE_RESERVED_REMOTE);
2938-
NODE_DEFINE_CONSTANT(constants, NGHTTP2_STREAM_STATE_HALF_CLOSED_LOCAL);
2939-
NODE_DEFINE_CONSTANT(constants, NGHTTP2_STREAM_STATE_HALF_CLOSED_REMOTE);
2940-
NODE_DEFINE_CONSTANT(constants, NGHTTP2_STREAM_STATE_CLOSED);
2941-
NODE_DEFINE_CONSTANT(constants, NGHTTP2_NO_ERROR);
2942-
NODE_DEFINE_CONSTANT(constants, NGHTTP2_PROTOCOL_ERROR);
2943-
NODE_DEFINE_CONSTANT(constants, NGHTTP2_INTERNAL_ERROR);
2944-
NODE_DEFINE_CONSTANT(constants, NGHTTP2_FLOW_CONTROL_ERROR);
2945-
NODE_DEFINE_CONSTANT(constants, NGHTTP2_SETTINGS_TIMEOUT);
2946-
NODE_DEFINE_CONSTANT(constants, NGHTTP2_STREAM_CLOSED);
2947-
NODE_DEFINE_CONSTANT(constants, NGHTTP2_FRAME_SIZE_ERROR);
2948-
NODE_DEFINE_CONSTANT(constants, NGHTTP2_REFUSED_STREAM);
2949-
NODE_DEFINE_CONSTANT(constants, NGHTTP2_CANCEL);
2950-
NODE_DEFINE_CONSTANT(constants, NGHTTP2_COMPRESSION_ERROR);
2951-
NODE_DEFINE_CONSTANT(constants, NGHTTP2_CONNECT_ERROR);
2952-
NODE_DEFINE_CONSTANT(constants, NGHTTP2_ENHANCE_YOUR_CALM);
2953-
NODE_DEFINE_CONSTANT(constants, NGHTTP2_INADEQUATE_SECURITY);
2954-
NODE_DEFINE_CONSTANT(constants, NGHTTP2_HTTP_1_1_REQUIRED);
2932+
Local<Array> name_for_error_code = Array::New(isolate);
2933+
2934+
#define NODE_NGHTTP2_ERROR_CODES(V) \
2935+
V(NGHTTP2_SESSION_SERVER); \
2936+
V(NGHTTP2_SESSION_CLIENT); \
2937+
V(NGHTTP2_STREAM_STATE_IDLE); \
2938+
V(NGHTTP2_STREAM_STATE_OPEN); \
2939+
V(NGHTTP2_STREAM_STATE_RESERVED_LOCAL); \
2940+
V(NGHTTP2_STREAM_STATE_RESERVED_REMOTE); \
2941+
V(NGHTTP2_STREAM_STATE_HALF_CLOSED_LOCAL); \
2942+
V(NGHTTP2_STREAM_STATE_HALF_CLOSED_REMOTE); \
2943+
V(NGHTTP2_STREAM_STATE_CLOSED); \
2944+
V(NGHTTP2_NO_ERROR); \
2945+
V(NGHTTP2_PROTOCOL_ERROR); \
2946+
V(NGHTTP2_INTERNAL_ERROR); \
2947+
V(NGHTTP2_FLOW_CONTROL_ERROR); \
2948+
V(NGHTTP2_SETTINGS_TIMEOUT); \
2949+
V(NGHTTP2_STREAM_CLOSED); \
2950+
V(NGHTTP2_FRAME_SIZE_ERROR); \
2951+
V(NGHTTP2_REFUSED_STREAM); \
2952+
V(NGHTTP2_CANCEL); \
2953+
V(NGHTTP2_COMPRESSION_ERROR); \
2954+
V(NGHTTP2_CONNECT_ERROR); \
2955+
V(NGHTTP2_ENHANCE_YOUR_CALM); \
2956+
V(NGHTTP2_INADEQUATE_SECURITY); \
2957+
V(NGHTTP2_HTTP_1_1_REQUIRED); \
2958+
2959+
#define V(name) \
2960+
NODE_DEFINE_CONSTANT(constants, name); \
2961+
name_for_error_code->Set(static_cast<int>(name), \
2962+
FIXED_ONE_BYTE_STRING(isolate, #name));
2963+
NODE_NGHTTP2_ERROR_CODES(V)
2964+
#undef V
29552965

29562966
NODE_DEFINE_HIDDEN_CONSTANT(constants, NGHTTP2_HCAT_REQUEST);
29572967
NODE_DEFINE_HIDDEN_CONSTANT(constants, NGHTTP2_HCAT_RESPONSE);
@@ -3016,6 +3026,9 @@ HTTP_STATUS_CODES(V)
30163026
target->Set(context,
30173027
FIXED_ONE_BYTE_STRING(isolate, "constants"),
30183028
constants).FromJust();
3029+
target->Set(context,
3030+
FIXED_ONE_BYTE_STRING(isolate, "nameForErrorCode"),
3031+
name_for_error_code).FromJust();
30193032
}
30203033
} // namespace http2
30213034
} // namespace node

test/parallel/test-http2-client-rststream-before-connect.js

+1-1
Original file line numberDiff line numberDiff line change
@@ -59,7 +59,7 @@ server.listen(0, common.mustCall(() => {
5959
req.on('error', common.expectsError({
6060
code: 'ERR_HTTP2_STREAM_ERROR',
6161
type: Error,
62-
message: `Stream closed with error code ${closeCode}`
62+
message: 'Stream closed with error code NGHTTP2_PROTOCOL_ERROR'
6363
}));
6464

6565
req.on('response', common.mustCall());

test/parallel/test-http2-client-stream-destroy-before-connect.js

+2-1
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,8 @@ server.on('stream', (stream) => {
1818
// system specific timings.
1919
stream.on('error', (err) => {
2020
assert.strictEqual(err.code, 'ERR_HTTP2_STREAM_ERROR');
21-
assert.strictEqual(err.message, 'Stream closed with error code 2');
21+
assert.strictEqual(err.message,
22+
'Stream closed with error code NGHTTP2_INTERNAL_ERROR');
2223
});
2324
stream.respond();
2425
stream.end();

test/parallel/test-http2-client-unescaped-path.js

+1-1
Original file line numberDiff line numberDiff line change
@@ -27,7 +27,7 @@ server.listen(0, common.mustCall(() => {
2727
req.on('error', common.expectsError({
2828
code: 'ERR_HTTP2_STREAM_ERROR',
2929
type: Error,
30-
message: 'Stream closed with error code 1'
30+
message: 'Stream closed with error code NGHTTP2_PROTOCOL_ERROR'
3131
}));
3232
req.on('close', common.mustCall(() => countdown.dec()));
3333
}

test/parallel/test-http2-compat-serverresponse-destroy.js

+2-2
Original file line numberDiff line numberDiff line change
@@ -58,7 +58,7 @@ server.listen(0, common.mustCall(() => {
5858
req.on('error', common.expectsError({
5959
code: 'ERR_HTTP2_STREAM_ERROR',
6060
type: Error,
61-
message: 'Stream closed with error code 2'
61+
message: 'Stream closed with error code NGHTTP2_INTERNAL_ERROR'
6262
}));
6363
req.on('close', common.mustCall(() => countdown.dec()));
6464

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

test/parallel/test-http2-info-headers-errors.js

+1-1
Original file line numberDiff line numberDiff line change
@@ -72,7 +72,7 @@ function runTest(test) {
7272
req.on('error', common.expectsError({
7373
code: 'ERR_HTTP2_STREAM_ERROR',
7474
type: Error,
75-
message: 'Stream closed with error code 2'
75+
message: 'Stream closed with error code NGHTTP2_INTERNAL_ERROR'
7676
}));
7777

7878
req.on('close', common.mustCall(() => {

test/parallel/test-http2-max-concurrent-streams.js

+1-1
Original file line numberDiff line numberDiff line change
@@ -50,7 +50,7 @@ server.listen(0, common.mustCall(() => {
5050
req.on('error', common.expectsError({
5151
code: 'ERR_HTTP2_STREAM_ERROR',
5252
type: Error,
53-
message: 'Stream closed with error code 7'
53+
message: 'Stream closed with error code NGHTTP2_REFUSED_STREAM'
5454
}));
5555
}
5656
}));

test/parallel/test-http2-misbehaving-flow-control-paused.js

+1-1
Original file line numberDiff line numberDiff line change
@@ -63,7 +63,7 @@ server.on('stream', (stream) => {
6363
stream.on('error', common.expectsError({
6464
code: 'ERR_HTTP2_STREAM_ERROR',
6565
type: Error,
66-
message: 'Stream closed with error code 3'
66+
message: 'Stream closed with error code NGHTTP2_FLOW_CONTROL_ERROR'
6767
}));
6868
stream.on('close', common.mustCall(() => {
6969
server.close();

test/parallel/test-http2-misbehaving-flow-control.js

+1-1
Original file line numberDiff line numberDiff line change
@@ -69,7 +69,7 @@ server.on('stream', (stream) => {
6969
stream.on('error', common.expectsError({
7070
code: 'ERR_HTTP2_STREAM_ERROR',
7171
type: Error,
72-
message: 'Stream closed with error code 3'
72+
message: 'Stream closed with error code NGHTTP2_FLOW_CONTROL_ERROR'
7373
}));
7474
stream.on('close', common.mustCall(() => {
7575
server.close(common.mustCall());

test/parallel/test-http2-misused-pseudoheaders.js

+1-1
Original file line numberDiff line numberDiff line change
@@ -41,7 +41,7 @@ server.listen(0, common.mustCall(() => {
4141
req.on('error', common.expectsError({
4242
code: 'ERR_HTTP2_STREAM_ERROR',
4343
type: Error,
44-
message: 'Stream closed with error code 2'
44+
message: 'Stream closed with error code NGHTTP2_INTERNAL_ERROR'
4545
}));
4646

4747
req.on('response', common.mustCall());

test/parallel/test-http2-multi-content-length.js

+1-1
Original file line numberDiff line numberDiff line change
@@ -58,7 +58,7 @@ server.listen(0, common.mustCall(() => {
5858
req.on('error', common.expectsError({
5959
code: 'ERR_HTTP2_STREAM_ERROR',
6060
type: Error,
61-
message: 'Stream closed with error code 1'
61+
message: 'Stream closed with error code NGHTTP2_PROTOCOL_ERROR'
6262
}));
6363
}
6464
}));

test/parallel/test-http2-options-max-headers-block-length.js

+1-1
Original file line numberDiff line numberDiff line change
@@ -38,6 +38,6 @@ server.listen(0, common.mustCall(() => {
3838
req.on('error', common.expectsError({
3939
code: 'ERR_HTTP2_STREAM_ERROR',
4040
type: Error,
41-
message: 'Stream closed with error code 7'
41+
message: 'Stream closed with error code NGHTTP2_REFUSED_STREAM'
4242
}));
4343
}));

test/parallel/test-http2-respond-file-fd-invalid.js

+1-1
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,7 @@ const {
1515
const errorCheck = common.expectsError({
1616
code: 'ERR_HTTP2_STREAM_ERROR',
1717
type: Error,
18-
message: `Stream closed with error code ${NGHTTP2_INTERNAL_ERROR}`
18+
message: 'Stream closed with error code NGHTTP2_INTERNAL_ERROR'
1919
}, 2);
2020

2121
const server = http2.createServer();

test/parallel/test-http2-respond-nghttperrors.js

+1-1
Original file line numberDiff line numberDiff line change
@@ -80,7 +80,7 @@ function runTest(test) {
8080
req.on('error', common.expectsError({
8181
code: 'ERR_HTTP2_STREAM_ERROR',
8282
type: Error,
83-
message: 'Stream closed with error code 2'
83+
message: 'Stream closed with error code NGHTTP2_INTERNAL_ERROR'
8484
}));
8585

8686
currentError = test;

test/parallel/test-http2-respond-with-fd-errors.js

+1-1
Original file line numberDiff line numberDiff line change
@@ -88,7 +88,7 @@ function runTest(test) {
8888
req.on('error', common.expectsError({
8989
code: 'ERR_HTTP2_STREAM_ERROR',
9090
type: Error,
91-
message: 'Stream closed with error code 2'
91+
message: 'Stream closed with error code NGHTTP2_INTERNAL_ERROR'
9292
}));
9393

9494
currentError = test;

test/parallel/test-http2-too-large-headers.js

+1-1
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,7 @@ server.listen(0, common.mustCall(() => {
2020
req.on('error', common.expectsError({
2121
code: 'ERR_HTTP2_STREAM_ERROR',
2222
type: Error,
23-
message: 'Stream closed with error code 11'
23+
message: 'Stream closed with error code NGHTTP2_ENHANCE_YOUR_CALM'
2424
}));
2525
req.on('close', common.mustCall((code) => {
2626
assert.strictEqual(code, NGHTTP2_ENHANCE_YOUR_CALM);

test/parallel/test-http2-too-many-headers.js

+1-1
Original file line numberDiff line numberDiff line change
@@ -23,7 +23,7 @@ server.listen(0, common.mustCall(() => {
2323
req.on('error', common.expectsError({
2424
code: 'ERR_HTTP2_STREAM_ERROR',
2525
type: Error,
26-
message: 'Stream closed with error code 11'
26+
message: 'Stream closed with error code NGHTTP2_ENHANCE_YOUR_CALM'
2727
}));
2828
req.on('close', common.mustCall((code) => {
2929
assert.strictEqual(code, NGHTTP2_ENHANCE_YOUR_CALM);

test/sequential/test-http2-max-session-memory.js

+1-1
Original file line numberDiff line numberDiff line change
@@ -30,7 +30,7 @@ server.listen(0, common.mustCall(() => {
3030
req.on('error', common.expectsError({
3131
code: 'ERR_HTTP2_STREAM_ERROR',
3232
type: Error,
33-
message: 'Stream closed with error code 11'
33+
message: 'Stream closed with error code NGHTTP2_ENHANCE_YOUR_CALM'
3434
}));
3535
req.on('close', common.mustCall(() => {
3636
server.close();

0 commit comments

Comments
 (0)