Skip to content

http_client, errors: migrate to use internal/errors - #14423

Closed
starkwang wants to merge 1 commit into
nodejs:masterfrom
starkwang:http-client-internal-errors
Closed

http_client, errors: migrate to use internal/errors#14423
starkwang wants to merge 1 commit into
nodejs:masterfrom
starkwang:http-client-internal-errors

Conversation

@starkwang

@starkwangstarkwang commented Jul 22, 2017

Copy link
Copy Markdown
Contributor

Ref: #11273

Checklist
  • make -j4 test (UNIX), or vcbuild test (Windows) passes
  • tests and/or benchmarks are included
  • documentation is changed or added
  • commit message follows commit guidelines
Affected core subsystem(s)

errors, http_client

@nodejs-github-botnodejs-github-bot added errors Issues and PRs related to JavaScript errors originated in Node.js core. http Issues or PRs related to the http subsystem. labels Jul 22, 2017
@refack

Copy link
Copy Markdown
Contributor

@starkwang thank you so much for helping with this!

We recently updated the recommended way to test internal Errors — https://github.com/nodejs/node/pull/14207/files
tl;dr need to test the message only if it's variable, and once is enough (in test/parallel/test-internal-errors.js).
IMHO the PR is good as is, but it would be great if you followed up and made it even better.

/cc @jasnell@fhinkel@Trott@mhdawson

@refack

Copy link
Copy Markdown
Contributor

Comment threadlib/internal/errors.js Outdated

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

FYI you could just use %s place holders, but IMHO this way is more readable.

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

But: consistency 😉

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

There is none anyway...
I'll open a PR to change them all.

@tniessen

Copy link
Copy Markdown
Member

Whoever lands this: I think the subsystem should be http_client with an underscore.

@starkwang
starkwangforce-pushed the http-client-internal-errors branch from 6031cca to 4ad89b7CompareJuly 22, 2017 16:29
@starkwang

Copy link
Copy Markdown
ContributorAuthor

@refack I've added some tests for the new errors in test/parallel/test-internal-errors.js😀

@TrottTrott added the semver-major PRs that contain breaking changes and should be released in the next major version. label Jul 22, 2017
@Trott

Copy link
Copy Markdown
Member

semver-major so pinging @nodejs/ctc for some reviews

@refackrefack left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

💯

@mcollinamcollina left a comment

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM

@addaleax

Copy link
Copy Markdown
Member

@starkwang Sorry to be a bummer, but can you rebase this against master? There are some merge conflicts here…

@starkwang
starkwangforce-pushed the http-client-internal-errors branch 2 times, most recently from c54858b to 4c62748CompareJuly 27, 2017 02:20
Comment threaddoc/api/errors.md Outdated

Copy link
Copy Markdown
ContributorAuthor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It seems that I missing some titles for errors.md in #14212 . So I added the missing titles in this PR

Comment threaddoc/api/errors.md Outdated

Copy link
Copy Markdown
ContributorAuthor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It seems that I missing some titles for errors.md in #14212 . So I added the missing titles in this PR

@starkwang

Copy link
Copy Markdown
ContributorAuthor

@addaleax I've just rebased the branch : )

@addaleax

Copy link
Copy Markdown
Member

@tniessentniessen left a comment

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

From using-internal-errors.md:

If the error message is not a constant string then tests to validate the formatting of the message based on the parameters used when creating the error should be added to test/parallel/test-internal-errors.js. These tests should validate all of the different ways parameters can be used to generate the final message string.

And this section:

In addition, there should also be tests which validate the use of the error based on where it is used in the codebase. For these tests, except in special cases, they should only validate that the expected code is received and NOT validate the message.

I don't exactly care about this, just remember that this PR does not strictly comply with these guidelines.

Thanks for your efforts @starkwang! 😃

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Unless I am missing something, it does not appear to be necessary to use a regular expression here, a string literal should work just fine. By the way, if you want to match an exact string using regular expressions, use start (^) and end markers ($). Otherwise, the match will succeed even if there is content before or after the expression:

constexpr=/The"method"argumentmustbeoftypestring/;conststr='The "method" argument must be of type string. Also, this sentence should not be here';expr.test(str)===true

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Same here, why is this a regular expression?

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Same here.

@starkwang
starkwangforce-pushed the http-client-internal-errors branch 3 times, most recently from 58fd145 to d4c91a7CompareJuly 28, 2017 02:42
@starkwangstarkwang changed the title http client, errors: migrate to use internal/errorshttp_client, errors: migrate to use internal/errorsJul 28, 2017
Comment threaddoc/api/errors.md Outdated

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Grammar: have been sent. Also, http probably refers to the protocol instead of the module name, so I would prefer HTTP over http.

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Used when new HTTP headers are added to a response, after the headers part has already been sent.

Comment threaddoc/api/errors.md Outdated

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

http probably refers to the protocol instead of the module name, so I would prefer HTTP over http.

Comment threaddoc/api/errors.md Outdated

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Grammar: that be passed. I would just say "... failed to parse the host or hostname option".

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Used when `hostname` can not be parsed from a provided URL.

Comment threaddoc/api/errors.md Outdated

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Grammar: when receive. Should probably be when receiving.

@refackrefackJul 29, 2017

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Used when a string that contains unescaped characters was received.

Comment threadlib/_http_client.js Outdated

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I don't have a strong opinion on this, I would prefer a more meaningful name for this error code. From the error code, the actual reason of the error is unclear, and the message implies that having the headers sent already is the only reason sending headers can fail, ever, and I am not too sure about that. Maybe something like ERR_HEADERS_SENT? Doesn't sound perfect either... cc @refack

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

ERR_HTTP_HEADERS_SENT

@refack

Copy link
Copy Markdown
Contributor

IMHO the documentation improvements should be non blockers, since simply migrating the Errors is of higher priority. But it's definatly nice to have while we wait for another @nodejs/ctc approval.

@Trott

Copy link
Copy Markdown
Member

This PR has http, internal errors, and is semver major. Seems like @jasnell should be all over it. Ping! :-D

@starkwang
starkwangforce-pushed the http-client-internal-errors branch from d4c91a7 to db8fb2aCompareJuly 30, 2017 13:41
@starkwang

Copy link
Copy Markdown
ContributorAuthor

Pushed commit to address comments

@refackrefack left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

💯

@refack

Copy link
Copy Markdown
Contributor

@tniessen

Copy link
Copy Markdown
Member

Landed in bdfbce9.

@tniessentniessen closed this Aug 1, 2017
tniessen pushed a commit that referenced this pull request Aug 1, 2017
PR-URL: #14423
Refs: #11273
Reviewed-By: Matteo Collina <matteo.collina@gmail.com>
Reviewed-By: Refael Ackermann <refack@gmail.com>
Reviewed-By: James M Snell <jasnell@gmail.com>
Reviewed-By: Tobias Nießen <tniessen@tnie.de>
MylesBorins added a commit to MylesBorins/node that referenced this pull request Sep 13, 2017
This error code originally landed in a semver-major commit and is used
by the ESM implementation. This backport includes the error message
and the documentation for the error.
I did attempt to write a test for this, but it did not seem possible
to catch an exception during import, I was also unable to execute
`node --experimental-modules` properly inside of a child_process.
I'll dig more into getting a test together, but we should backport
this fix in the mean time.
Refs: nodejs#14423Fixes: nodejs#15374
MylesBorins added a commit that referenced this pull request Sep 14, 2017
This error code originally landed in a semver-major commit and is used
by the ESM implementation. This backport includes the error message
and the documentation for the error.
I did attempt to write a test for this, but it did not seem possible
to catch an exception during import, I was also unable to execute
`node --experimental-modules` properly inside of a child_process.
I'll dig more into getting a test together, but we should backport
this fix in the mean time.
Refs: #14423Fixes: #15374
MylesBorins added a commit that referenced this pull request Sep 14, 2017
This error code originally landed in a semver-major commit and is used
by the ESM implementation. This backport includes the error message
and the documentation for the error.
I did attempt to write a test for this, but it did not seem possible
to catch an exception during import, I was also unable to execute
`node --experimental-modules` properly inside of a child_process.
I'll dig more into getting a test together, but we should backport
this fix in the mean time.
Refs: #14423Fixes: #15374
PR-URL: #15388
Reviewed-By: Bradley Farias <bradley.meck@gmail.com>
Reviewed-By: James M Snell <jasnell@gmail.com>
Sign up for freeto join this conversation on GitHub. Already have an account? Sign in to comment

Labels

errorsIssues and PRs related to JavaScript errors originated in Node.js core.httpIssues or PRs related to the http subsystem.semver-majorPRs 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.

8 participants

@starkwang@refack@tniessen@Trott@addaleax@mcollina@jasnell@nodejs-github-bot