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

net: throw error if port does not exist in options #22085

Conversation

yanivfriedensohn
Copy link
Contributor

@yanivfriedensohn yanivfriedensohn commented Aug 2, 2018

Throw error ERR_PROPERTY_NOT_IN_OBJECT if the port property does not
exist in the options object argument when calling server.listen().

Refs: #16712

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

#SimilarWeb_RnD

@nodejs-github-bot nodejs-github-bot added errors Issues and PRs related to JavaScript errors originated in Node.js core. net Issues and PRs related to the net subsystem. labels Aug 2, 2018
@jasnell jasnell added the semver-major PRs that contain breaking changes and should be released in the next major version. label Aug 3, 2018
@jasnell
Copy link
Member

jasnell commented Aug 3, 2018

Semver-major because of the addition of a new throw.

@nodejs/tsc ... PTAL. I'm not yet convinced this is definitely something we should do.

@Trott
Copy link
Member

Trott commented Aug 4, 2018

Hi, @yanivfriedensohn and welcome! Thanks for the PR.

I think the added error is not quite right. If I understand correctly, port is not required. Rather, one of either port or path is required. Might it not be better to improve the message displayed for the existing ERR_INVALID_OPT_VALUE error to indicate that rather than add a new error?

@yanivfriedensohn
Copy link
Contributor Author

Hi @Trott, based on your suggestions, I added an additional error message argument to ERR_INVALID_OPT_VALUE and removed ERR_PROPERTY_NOT_IN_OBJECT.

@yanivfriedensohn yanivfriedensohn force-pushed the throw-error-if-port-does-not-exist-in-options branch from c75c291 to dc961c8 Compare August 4, 2018 19:56
@maclover7
Copy link
Contributor

@yanivfriedensohn Would you be able to add some tests for the new behavior? We can run CI on this after that

@maclover7 maclover7 added the wip Issues and PRs that are still a work in progress. label Aug 11, 2018
@joyeecheung
Copy link
Member

How does this fix #16712 ? It requested

APIs that accept a host should respect their port number to avoid confusion and inconsistency. I would also suggest that server.listen() should only support hostname instead of host, leaving parsing hosts to userland... but that would be a breaking change (and should probably be a separate issue).

@joyeecheung
Copy link
Member

Note that server.listen() works like server.listen(0) so to say that port or path must be specified is not entirely accurate..

@yanivfriedensohn yanivfriedensohn force-pushed the throw-error-if-port-does-not-exist-in-options branch 2 times, most recently from 8bed77c to 7498e3c Compare August 13, 2018 21:36
@yanivfriedensohn
Copy link
Contributor Author

@maclover7 I added tests for the additional error message.

@joyeecheung this fixes:

The { host : 'localhost' } error message would be good to fix but the other "expected behaviors" could potentially create (possibly severe) ecosystem fallout for not enough value to take the risk.

The message mentions that port or path are required in options. Should I rephrase the message to make it more clear?

@joyeecheung
Copy link
Member

@yanivfriedensohn In that case please do not put Fixes in the PR/commit message as landing it would close that issue automatically even though it's not fully fixed.

lib/net.js Outdated
@@ -1496,7 +1496,15 @@ Server.prototype.listen = function(...args) {
return this;
}

throw new ERR_INVALID_OPT_VALUE('options', util.inspect(options));
let additionalMessage;
if (typeof options === 'object' &&
Copy link
Member

Choose a reason for hiding this comment

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

typeof options === 'object' here is always true since it's normalized before

lib/net.js Outdated
additionalMessage = '"port" or "path" must be specified in options.';
}

throw new ERR_INVALID_OPT_VALUE('options', util.inspect(options),
Copy link
Member

Choose a reason for hiding this comment

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

This error message will not be accurate since options is an argument, not an option value - the user does not pass { options: { ... } } to this method. ERR_INVALID_ARG_VALUE may be more accurate.

@yanivfriedensohn yanivfriedensohn force-pushed the throw-error-if-port-does-not-exist-in-options branch from 7498e3c to 4862c1f Compare August 15, 2018 18:35
@yanivfriedensohn
Copy link
Contributor Author

@joyeecheung following your suggestion, I used ERR_INVALID_ARG_VALUE instead of ERR_INVALID_OPT_VALUE and reverted the change to ERR_INVALID_OPT_VALUE.

@Trott Trott removed the wip Issues and PRs that are still a work in progress. label Aug 15, 2018
@Trott
Copy link
Member

Trott commented Aug 15, 2018

Tests have been added so I've removed the in progress label. /cc @maclover7 Feel free to add it back if it still applies.

@yanivfriedensohn
Copy link
Contributor Author

@joyeecheung is this ready for CI?

@joyeecheung
Copy link
Member

@Trott Trott added author ready PRs that have at least one approval, no pending requests for changes, and a CI started. and removed author ready PRs that have at least one approval, no pending requests for changes, and a CI started. labels Aug 22, 2018
@Trott Trott force-pushed the throw-error-if-port-does-not-exist-in-options branch from 4862c1f to 630d987 Compare August 22, 2018 04:19
@Trott
Copy link
Member

Trott commented Aug 22, 2018

Rebased and force pushed to resolve the dreaded jinja LICENSE CRLF thing. (I think we'll all be happy when that problem is a few weeks in the past.)

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

@yanivfriedensohn
Copy link
Contributor Author

@Trott issue #18435 seems to be related to the failed test.

@Trott
Copy link
Member

Trott commented Aug 23, 2018

@yanivfriedensohn
Copy link
Contributor Author

@Trott is this author ready?

@BridgeAR BridgeAR requested a review from a team August 31, 2018 20:09
@BridgeAR BridgeAR added the author ready PRs that have at least one approval, no pending requests for changes, and a CI started. label Aug 31, 2018
Copy link
Member

@mcollina mcollina left a comment

Choose a reason for hiding this comment

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

LGTM

@addaleax
Copy link
Member

addaleax commented Sep 2, 2018

Landed in 4a0466f 🎉

@addaleax addaleax closed this Sep 2, 2018
addaleax pushed a commit that referenced this pull request Sep 2, 2018
Throw error ERR_INVALID_ARG_VALUE if the port and path properties
do not exist in the options object argument when calling
server.listen().

Refs: #16712

PR-URL: #22085
Reviewed-By: Joyee Cheung <joyeec9h3@gmail.com>
Reviewed-By: Ruben Bridgewater <ruben@bridgewater.de>
Reviewed-By: Matteo Collina <matteo.collina@gmail.com>
@yanivfriedensohn yanivfriedensohn deleted the throw-error-if-port-does-not-exist-in-options branch June 21, 2019 10:35
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
author ready PRs that have at least one approval, no pending requests for changes, and a CI started. errors Issues and PRs related to JavaScript errors originated in Node.js core. net Issues and PRs related to the net 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.

9 participants