-
Notifications
You must be signed in to change notification settings - Fork 29.9k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
lib, test: migrate _http_outgoing.js's remaining errors to internal/errors.js #17837
lib, test: migrate _http_outgoing.js's remaining errors to internal/errors.js #17837
Conversation
@@ -26,7 +26,10 @@ const http = require('http'); | |||
|
|||
const server = http.Server(common.mustCall(function(req, res) { | |||
res.on('error', common.mustCall(function onResError(err) { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Since common.expectsError
returns a function wrapped in common.mustCall
that can be used as callbacks, can you simplify this to:
res.on('error', common.expectsError({
code: 'ERR_STREAM_WRITE_AFTER_END',
type: Error
}));
?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Done!
(err) => { | ||
return ((err instanceof Error) && /Cannot pipe, not readable/.test(err)); | ||
}, | ||
common.expectsError({ |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
common.expectsError
can take a function and wraps it in assert.throws
, can you simplify this to
common.expectsError(
() => { outgoingMessage.pipe(outgoingMessage); },
{
code: 'ERR_STREAM_CANNOT_PIPE',
type: Error
}
);
?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Done!
@@ -18,7 +17,10 @@ const server = http.createServer(common.mustCall(function(req, res) { | |||
res.end(); | |||
myStream.emit('data', 'some data'); | |||
res.on('error', common.mustCall(function(err) { | |||
assert.strictEqual(err.message, 'write after end'); | |||
common.expectsError({ |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Can you simplify this to
res.on('error', common.expectsError({
code: 'ERR_STREAM_WRITE_AFTER_END',
type: Error
}));
?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Done!
A couple of lib/_http_outgoing.js's errors were still in the "old style": `throw new Error(<some message here>)`. This commit migrates those 2 old style errors to the "new style": internal/errors.js's error-system. In the future, changes to these errors' messages won't break semver-major status. With the old style, changes to these errors' messages broke semver-major status. It was inconvenient. Refs: #17709
Two of _http_outgoing.js's errors were migrated to the internal/errors.js system. This commit adapts _http_outgoing.js's tests accordingly. Refs: #17709
_http_outgoing.js's tests perform error-checks. They ensure that appropriate errors are thrown in the appropriate circumstances. A few error-checks were bloated. They used unnecessary intermediate functions. E.g. there were unnecessary combinations of `common.mustCall()` & `common.expectsError()` and `common.expectsError()` & `assert.throws()`. This commit removes those unnecessary intermediate functions. This simplifies the given error-checks.
|
||
// Fix for https://github.com/nodejs/node/issues/14368 | ||
|
||
const server = http.createServer(handle); | ||
|
||
function handle(req, res) { | ||
res.on('error', common.mustCall((err) => { | ||
assert.strictEqual(err.message, 'write after end'); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Oh, I missed this. I'll fix it soon!
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
^^ Addressed this remark in the comment below.
common.expectsError({ | ||
code: 'ERR_STREAM_WRITE_AFTER_END', | ||
type: Error | ||
})(err); | ||
server.close(); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Never mind. I thought I could remove the common.mustCall()
on line 11
, and simplify it to just common.expectsError()
.
That's what I did in test-pipe-outgoing-message-data-emitted-after-ended.js
on lines 19-21
.
However, I can't. This block performs server.close()
in addition to common.expectsError()
. That additional functionality prevents me from simplifying common.mustCall() => common.expectsError()
.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The way to handle that would be to register two on('error') handlers, one with the expectsError()
check and the second with the server.close()
call.
@joyeecheung Are there any other concerns? |
These needs two TSC approvals. cc @nodejs/tsc |
@acparas failures seems to to be unrelated to this change. |
Landed in d3ac18a, thanks! |
A couple of lib/_http_outgoing.js's errors were still in the "old style": `throw new Error(<some message here>)`. This commit migrates those 2 old style errors to the "new style": internal/errors.js's error-system. In the future, changes to these errors' messages won't break semver-major status. With the old style, changes to these errors' messages broke semver-major status. It was inconvenient. Refs: #17709 PR-URL: #17837 Reviewed-By: Joyee Cheung <joyeec9h3@gmail.com> Reviewed-By: Luigi Pinca <luigipinca@gmail.com> Reviewed-By: James M Snell <jasnell@gmail.com>
cc @jasnell @joyeecheung
A couple of
lib/_http_outgoing.js
's errors were still in the "old style":throw new Error(<some message here>)
.This PR migrates those 2 old style errors to the "new style":
internal/errors.js
's error-system.In the future, changes to these errors' messages won't break semver-major status. With the old style, changes to these errors' messages broke semver-major status. It was inconvenient.
This PR also adapts
_http_outgoing.js
's tests accordingly.Refs: #17709
Checklist
make -j4 test
(UNIX), orvcbuild test
(Windows) passesAffected core subsystem(s)
lib, test