diff --git a/lib/internal/http2/core.js b/lib/internal/http2/core.js index 010bec55451c83..a159b88ae84d50 100644 --- a/lib/internal/http2/core.js +++ b/lib/internal/http2/core.js @@ -62,7 +62,7 @@ const { } = require('timers'); const { ShutdownWrap, WriteWrap } = process.binding('stream_wrap'); -const { constants } = binding; +const { constants, nameForErrorCode } = binding; const NETServer = net.Server; const TLSServer = tls.Server; @@ -1841,7 +1841,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; diff --git a/src/node_http2.cc b/src/node_http2.cc index a11a0bc87b82b1..67c5c67982a178 100644 --- a/src/node_http2.cc +++ b/src/node_http2.cc @@ -2857,29 +2857,39 @@ void Initialize(Local target, session->GetFunction()).FromJust(); Local 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 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(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); @@ -2944,6 +2954,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 diff --git a/test/parallel/test-http2-client-rststream-before-connect.js b/test/parallel/test-http2-client-rststream-before-connect.js index 0b07ebe1051e7b..57a9580f9407d7 100644 --- a/test/parallel/test-http2-client-rststream-before-connect.js +++ b/test/parallel/test-http2-client-rststream-before-connect.js @@ -47,7 +47,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()); diff --git a/test/parallel/test-http2-client-stream-destroy-before-connect.js b/test/parallel/test-http2-client-stream-destroy-before-connect.js index a2412b9f1d646a..884a38fac6f71d 100644 --- a/test/parallel/test-http2-client-stream-destroy-before-connect.js +++ b/test/parallel/test-http2-client-stream-destroy-before-connect.js @@ -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(); diff --git a/test/parallel/test-http2-client-unescaped-path.js b/test/parallel/test-http2-client-unescaped-path.js index 190f8ce75e8917..ff122a02ca1a68 100644 --- a/test/parallel/test-http2-client-unescaped-path.js +++ b/test/parallel/test-http2-client-unescaped-path.js @@ -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())); } diff --git a/test/parallel/test-http2-compat-serverresponse-destroy.js b/test/parallel/test-http2-compat-serverresponse-destroy.js index f890346dbf4303..8ee52a74ab4e81 100644 --- a/test/parallel/test-http2-compat-serverresponse-destroy.js +++ b/test/parallel/test-http2-compat-serverresponse-destroy.js @@ -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())); diff --git a/test/parallel/test-http2-info-headers-errors.js b/test/parallel/test-http2-info-headers-errors.js index 230a1328ed1550..437add098b8a9f 100644 --- a/test/parallel/test-http2-info-headers-errors.js +++ b/test/parallel/test-http2-info-headers-errors.js @@ -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(() => { diff --git a/test/parallel/test-http2-max-concurrent-streams.js b/test/parallel/test-http2-max-concurrent-streams.js index ffc04e98f134b2..b270d6cc6aff31 100644 --- a/test/parallel/test-http2-max-concurrent-streams.js +++ b/test/parallel/test-http2-max-concurrent-streams.js @@ -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' })); } })); diff --git a/test/parallel/test-http2-misbehaving-flow-control-paused.js b/test/parallel/test-http2-misbehaving-flow-control-paused.js index d69e0fd802979a..60a2cdabf847d9 100644 --- a/test/parallel/test-http2-misbehaving-flow-control-paused.js +++ b/test/parallel/test-http2-misbehaving-flow-control-paused.js @@ -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(); diff --git a/test/parallel/test-http2-misbehaving-flow-control.js b/test/parallel/test-http2-misbehaving-flow-control.js index 161a88ea1fb407..f2da0ba56c8e67 100644 --- a/test/parallel/test-http2-misbehaving-flow-control.js +++ b/test/parallel/test-http2-misbehaving-flow-control.js @@ -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()); diff --git a/test/parallel/test-http2-misused-pseudoheaders.js b/test/parallel/test-http2-misused-pseudoheaders.js index b47462b14fd0e1..e9253baa74ad1d 100644 --- a/test/parallel/test-http2-misused-pseudoheaders.js +++ b/test/parallel/test-http2-misused-pseudoheaders.js @@ -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()); diff --git a/test/parallel/test-http2-multi-content-length.js b/test/parallel/test-http2-multi-content-length.js index 4d18356f127da0..c64b803a0ecca3 100644 --- a/test/parallel/test-http2-multi-content-length.js +++ b/test/parallel/test-http2-multi-content-length.js @@ -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' })); } })); diff --git a/test/parallel/test-http2-options-max-headers-block-length.js b/test/parallel/test-http2-options-max-headers-block-length.js index a728c28c6576d4..0706e6a83e6d48 100644 --- a/test/parallel/test-http2-options-max-headers-block-length.js +++ b/test/parallel/test-http2-options-max-headers-block-length.js @@ -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' })); })); diff --git a/test/parallel/test-http2-respond-file-fd-invalid.js b/test/parallel/test-http2-respond-file-fd-invalid.js index 5dbb42e4788a7a..21fcf790b449eb 100644 --- a/test/parallel/test-http2-respond-file-fd-invalid.js +++ b/test/parallel/test-http2-respond-file-fd-invalid.js @@ -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(); diff --git a/test/parallel/test-http2-respond-nghttperrors.js b/test/parallel/test-http2-respond-nghttperrors.js index 5ec953c5442360..ad9eee0d59fecc 100644 --- a/test/parallel/test-http2-respond-nghttperrors.js +++ b/test/parallel/test-http2-respond-nghttperrors.js @@ -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; diff --git a/test/parallel/test-http2-respond-with-fd-errors.js b/test/parallel/test-http2-respond-with-fd-errors.js index 99a5273df3c0d9..0eccd231c63a2e 100644 --- a/test/parallel/test-http2-respond-with-fd-errors.js +++ b/test/parallel/test-http2-respond-with-fd-errors.js @@ -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; diff --git a/test/parallel/test-http2-server-rst-stream.js b/test/parallel/test-http2-server-rst-stream.js index 6e4e9ccb88e611..402ff07fa9d0a0 100644 --- a/test/parallel/test-http2-server-rst-stream.js +++ b/test/parallel/test-http2-server-rst-stream.js @@ -18,10 +18,10 @@ const { const tests = [ [NGHTTP2_NO_ERROR, false], [NGHTTP2_NO_ERROR, false], - [NGHTTP2_PROTOCOL_ERROR, true, 1], + [NGHTTP2_PROTOCOL_ERROR, true, 'NGHTTP2_PROTOCOL_ERROR'], [NGHTTP2_CANCEL, false], - [NGHTTP2_REFUSED_STREAM, true, 7], - [NGHTTP2_INTERNAL_ERROR, true, 2] + [NGHTTP2_REFUSED_STREAM, true, 'NGHTTP2_REFUSED_STREAM'], + [NGHTTP2_INTERNAL_ERROR, true, 'NGHTTP2_INTERNAL_ERROR'] ]; const server = http2.createServer(); diff --git a/test/parallel/test-http2-too-large-headers.js b/test/parallel/test-http2-too-large-headers.js index 7a7082736160f8..ad7a24f39b2fa2 100644 --- a/test/parallel/test-http2-too-large-headers.js +++ b/test/parallel/test-http2-too-large-headers.js @@ -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); diff --git a/test/parallel/test-http2-too-many-headers.js b/test/parallel/test-http2-too-many-headers.js index f05511cff657e0..9b57060be695bb 100644 --- a/test/parallel/test-http2-too-many-headers.js +++ b/test/parallel/test-http2-too-many-headers.js @@ -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); diff --git a/test/sequential/test-http2-max-session-memory.js b/test/sequential/test-http2-max-session-memory.js index e16000d1261ab0..d6d3bf935db801 100644 --- a/test/sequential/test-http2-max-session-memory.js +++ b/test/sequential/test-http2-max-session-memory.js @@ -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();