Skip to content
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

Closed
wants to merge 3 commits into from
Closed

lib, test: migrate _http_outgoing.js's remaining errors to internal/errors.js #17837

wants to merge 3 commits into from

Conversation

b0yfriend
Copy link
Contributor

@b0yfriend b0yfriend commented Dec 23, 2017

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), or vcbuild test (Windows) passes
  • tests and/or benchmarks are included
  • commit message follows commit guidelines
Affected core subsystem(s)

lib, test

@nodejs-github-bot nodejs-github-bot added the http Issues or PRs related to the http subsystem. label Dec 23, 2017
@joyeecheung joyeecheung added the errors Issues and PRs related to JavaScript errors originated in Node.js core. label Dec 23, 2017
@@ -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) {
Copy link
Member

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
}));

?

Copy link
Contributor Author

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({
Copy link
Member

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
  }
);

?

Copy link
Contributor Author

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({
Copy link
Member

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
}));

?

Copy link
Contributor Author

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');
Copy link
Contributor Author

@b0yfriend b0yfriend Dec 24, 2017

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!

Copy link
Contributor Author

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();
Copy link
Contributor Author

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().

Copy link
Member

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.

@b0yfriend
Copy link
Contributor Author

@joyeecheung Are there any other concerns?

@joyeecheung
Copy link
Member

These needs two TSC approvals. cc @nodejs/tsc

CI: https://ci.nodejs.org/job/node-test-pull-request/12289/

@joyeecheung joyeecheung added the semver-major PRs that contain breaking changes and should be released in the next major version. label Dec 24, 2017
@b0yfriend
Copy link
Contributor Author

Three raspbian builds failed. How do we handle this?

screen shot 2017-12-24 at 2 48 00 pm

@lpinca
Copy link
Member

lpinca commented Dec 25, 2017

@acparas failures seems to to be unrelated to this change.

@joyeecheung joyeecheung added the author ready PRs that have at least one approval, no pending requests for changes, and a CI started. label Dec 27, 2017
@joyeecheung
Copy link
Member

Landed in d3ac18a, thanks!

joyeecheung pushed a commit that referenced this pull request Dec 27, 2017
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>
@joyeecheung joyeecheung removed the author ready PRs that have at least one approval, no pending requests for changes, and a CI started. label Dec 27, 2017
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
errors Issues and PRs related to JavaScript errors originated in Node.js core. http Issues or PRs related to the http subsystem. semver-major PRs that contain breaking changes and should be released in the next major version.
Projects
None yet
Development

Successfully merging this pull request may close these issues.

5 participants