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/net: Convert to using internal/errors #14782

Closed
wants to merge 10 commits into
base: master
from

Conversation

@pmatzavin
Contributor

pmatzavin commented Aug 12, 2017

Covert lib/net.js over to using lib/internal/errors.js

Ref: #11273

I have not addressed the cases that use errnoException(),
for reasons described in GH-12926

  • Replace thrown errors in lib/net.js
    with errors from lib/internal/errors
  • Update tests according to the above modification
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)

lib/net, doc

Show outdated Hide outdated doc/api/errors.md Outdated
@Trott

Hi @pmatzavin! Welcome and thanks for the PR! I left a question/suggestion for a change.

@refack refack added the semver-major label Aug 12, 2017

@pmatzavin

This comment has been minimized.

Show comment
Hide comment
@pmatzavin

pmatzavin Aug 15, 2017

Contributor

Hi @Trott! Thanks for the help and the suggestion. I am traveling right now without my laptop. I will update my PR by this Saturday.

Contributor

pmatzavin commented Aug 15, 2017

Hi @Trott! Thanks for the help and the suggestion. I am traveling right now without my laptop. I will update my PR by this Saturday.

@Trott Trott dismissed their stale review Aug 19, 2017

discussion happened, dismissing review

@Trott

This comment has been minimized.

Show comment
Hide comment
@Trott

Trott Aug 19, 2017

Member

@nodejs/ctc This is semver-major, needs some CTC reviews.

Member

Trott commented Aug 19, 2017

@nodejs/ctc This is semver-major, needs some CTC reviews.

pmatzavin added a commit to pmatzavin/node that referenced this pull request Aug 20, 2017

lib/net: Convert to using internal/errors
Covert lib/net.js over to using lib/internal/errors.js

Ref: nodejs#11273

I have not addressed the cases that use errnoException(),
for reasons described in nodejsGH-12926

- Replace thrown errors in lib/net.js
  with errors from lib/internal/errors.
  The ERR_INVALID_OPT_VALUE error have been used
  in the Server.prototype.listen() method
  after a discussion in Ref: nodejs#14782
- Update tests according to the above modifications
@pmatzavin

This comment has been minimized.

Show comment
Hide comment
@pmatzavin

pmatzavin Aug 20, 2017

Contributor

updated

Contributor

pmatzavin commented Aug 20, 2017

updated

@refack

refack approved these changes Aug 20, 2017

LGTM
(just some nits)

Show outdated Hide outdated test/parallel/test-net-connect-options-port.js Outdated
Show outdated Hide outdated test/parallel/test-net-localerror.js Outdated
Show outdated Hide outdated test/parallel/test-net-server-options.js Outdated
@refack

This comment has been minimized.

Show comment
Hide comment
@refack

refack Aug 20, 2017

Member

Hello @pmatzavin and welcome. Thank you very much for the contribution 🥇
If you haven't already, it's recommended you take a look at CONTRIBUTING.md guide (especialy the part about "discuss and update"). Customarily PRs are kept open for at least 48 hour so that anyone interested gets a chance to comment or review.
About Error migrations, since they are semver-major they require 2 CTC members' approval (which can take longer than usual PR approval). A consequence of that is that this PR might become conflicted with master, so you might be asked to rebase it late.
Anyway thank you for the contribution, and good luck 🎉

P.S. If you have any question you can also feel free to contact me directly (@ mention, email, IM, or IRC)

Member

refack commented Aug 20, 2017

Hello @pmatzavin and welcome. Thank you very much for the contribution 🥇
If you haven't already, it's recommended you take a look at CONTRIBUTING.md guide (especialy the part about "discuss and update"). Customarily PRs are kept open for at least 48 hour so that anyone interested gets a chance to comment or review.
About Error migrations, since they are semver-major they require 2 CTC members' approval (which can take longer than usual PR approval). A consequence of that is that this PR might become conflicted with master, so you might be asked to rebase it late.
Anyway thank you for the contribution, and good luck 🎉

P.S. If you have any question you can also feel free to contact me directly (@ mention, email, IM, or IRC)

@refack refack added this to In Progress in Error Codes Aug 20, 2017

Show outdated Hide outdated lib/net.js Outdated
@rvagg

This comment has been minimized.

Show comment
Hide comment
@rvagg

rvagg Aug 20, 2017

Member

SGTM, but I defer to @jasnell on the integration with the full new error messaging approach, when he gives a +1 then consider mine in here too

Member

rvagg commented Aug 20, 2017

SGTM, but I defer to @jasnell on the integration with the full new error messaging approach, when he gives a +1 then consider mine in here too

@refack

refack approved these changes Aug 21, 2017

Small non blocking nit

Show outdated Hide outdated lib/net.js Outdated
@refack

refack approved these changes Aug 21, 2017

💯

@refack

This comment has been minimized.

Show comment
Hide comment
@refack
Member

refack commented Aug 21, 2017

@jasnell PTAL

Show outdated Hide outdated lib/net.js Outdated
@jasnell

A few nits but generally LGTM

pmatzavin added a commit to pmatzavin/node that referenced this pull request Aug 24, 2017

[fixup] lib/net.js update createHandle() err
- Create a new error 'ERR_INVALID_FD_TYPE'
  in lib/internal/errors.js,
  following the corresponding discussion at Ref: nodejs#14782.
  This error should be thrown
  when a file descriptor type is not valid.
- add test for the new err in test-internal-errors.js
- update the error doc in errors.md
- use the new err in createHandle() in lib/net.js
- Add brackets {} in arrow function in test-net-localerror.js
  to match the typical source code's format.
@pmatzavin

This comment has been minimized.

Show comment
Hide comment
@pmatzavin

pmatzavin Aug 25, 2017

Contributor

@refack There was no test for the fd error thrown in the lib/net.js Socket() constructor so I added a test in a new file test/parallel/test-net-socket-fd-error.js PTAL. Sorry for the late update.

Contributor

pmatzavin commented Aug 25, 2017

@refack There was no test for the fd error thrown in the lib/net.js Socket() constructor so I added a test in a new file test/parallel/test-net-socket-fd-error.js PTAL. Sorry for the late update.

Show outdated Hide outdated lib/net.js Outdated
@BridgeAR

Thanks a lot for your contribution. It looks pretty good overall. A few Error classes seemed to be mistaken though.

Besides that it would be nice to use common.expectsError(throwingFunction, options) instead of assert.throws(throwingFunction, common.expectsError(options)) but this should not block the PR.

Show outdated Hide outdated lib/net.js Outdated
Show outdated Hide outdated test/parallel/test-net-server-listen-options.js Outdated
Show outdated Hide outdated test/parallel/test-net-localerror.js Outdated
}
if (!isLegalPort(port)) {
throw new RangeError('"port" option should be >= 0 and < 65536: ' + port);
throw new errors.RangeError('ERR_SOCKET_BAD_PORT', port);

This comment has been minimized.

@BridgeAR

BridgeAR Aug 29, 2017

Member

The error type must also be able to handle the provided port.

@BridgeAR

BridgeAR Aug 29, 2017

Member

The error type must also be able to handle the provided port.

This comment has been minimized.

@pmatzavin

pmatzavin Aug 29, 2017

Contributor

I have made a change to include the port in the err msg if the port arg is passed to the error constructor.

@pmatzavin

pmatzavin Aug 29, 2017

Contributor

I have made a change to include the port in the err msg if the port arg is passed to the error constructor.

Show outdated Hide outdated lib/internal/errors.js Outdated
@BridgeAR

This comment has been minimized.

Show comment
Hide comment
@BridgeAR

BridgeAR Sep 24, 2017

Member

@mhdawson done in #15589

@pmatzavin this needs a rebase and it would be nice to add address the comments. Otherwise this is ready to go.

Member

BridgeAR commented Sep 24, 2017

@mhdawson done in #15589

@pmatzavin this needs a rebase and it would be nice to add address the comments. Otherwise this is ready to go.

pmatzavin added some commits Aug 11, 2017

lib/net: Convert to using internal/errors
Covert lib/net.js over to using lib/internal/errors.js

Ref: #11273

I have not addressed the cases that use errnoException(),
for reasons described in GH-12926

- Replace thrown errors in lib/net.js
  with errors from lib/internal/errors.
  The ERR_INVALID_OPT_VALUE error have been used
  in the Server.prototype.listen() method
  after a discussion in Ref: #14782
- Update tests according to the above modifications
[fixup] lib/net: update tests
- refactor the portTypeError and portRangeError assertions,
  by passing the expected call count to common.expectsError in
  test-net-connect-options-port.js
  (Each syncFailToConnect() call will call 4 or 2 times the
  doConnect() method, wich returns an array of size 6,
  so the call counts are 96 and 168 for portTypeError and
  portRangeError respectively)
- refactor the connect() method in test-net-localerror.js,
  by removing the reduntant assert
  and use the common.expectsError() assertion
- move require('../common') to the top in test-net-server-options.js
[fixup] lib/net: refac ERR_INVALID_ARG_TYPE err
- refactor the valid types argument of ERR_INVALID_ARG_TYPE errors,
  to be a string instead of an array when the number of valid types
  equals 1, in lib/net.js
[fixup] lib/net: update Server.listen() err msg
replace "listen options" with "options"
[fixup] lib/net.js update createHandle() err
- Create a new error 'ERR_INVALID_FD_TYPE'
  in lib/internal/errors.js,
  following the corresponding discussion at Ref: #14782.
  This error should be thrown
  when a file descriptor type is not valid.
- add test for the new err in test-internal-errors.js
- update the error doc in errors.md
- use the new err in createHandle() in lib/net.js
- Add brackets {} in arrow function in test-net-localerror.js
  to match the typical source code's format.
[fixup] lib/net: ERR_INVALID_FD_TYPE add test
- add missing test for the 'ERR_INVALID_FD_TYPE' err that is thrown
  from the net.Socket constructor
- correct the err type from Error to TypeError
[fixup] lib/net: correct err types
- correct 'ERR_INVALID_IP_ADDRESS' type to TypeError err in net.js
- correct 'ERR_SOCKET_BAD_PORT' type to RangeError in net.js
- correct 'ERR_INVALID_OPT_VALUE' type to Error in net.js
- pass the port value to the the 'ERR_SOCKET_BAD_PORT' err in net.js
[fixup] lib/net: ERR_SOCKET_BAD_PORT handle port
- Modify the ERR_SOCKET_BAD_PORT definition in internal/errors.js
  to include the specified port in the err msg, if the port
  arg is passed to the err constructor.
- Add tests for ERR_SOCKET_BAD_PORT msg in test-internal-errors.js
[fixup] lib/net: simplify err ERR_SOCKET_BAD_PORT
- simplify the ERR_SOCKET_BAD_PORT error definition in errors.js
  by replacing the cb arg with the string:
  'Port should be > 0 and < 65536. Received %s.'
- update the ERR_SOCKET_BAD_PORT test in test-internal-errors.js
- update the ERR_SOCKET_BAD_PORT constructor call in
  lib/dgram.js and lib/dns to include the actual port
  as the second arg
- update the already existing ERR_SOCKET_BAD_PORT message
  assertion in test-dns.js, to include the actual port.
@jasnell

This comment has been minimized.

Show comment
Hide comment
@jasnell

jasnell Sep 25, 2017

Member

I went ahead and rebased the branch.

Member

jasnell commented Sep 25, 2017

I went ahead and rebased the branch.

@jasnell

This comment has been minimized.

Show comment
Hide comment
@@ -1065,7 +1071,10 @@ function lookupAndConnect(self, options) {
}
if (options.lookup && typeof options.lookup !== 'function')
throw new TypeError('"lookup" option should be a function');
throw new errors.TypeError('ERR_INVALID_ARG_TYPE',

This comment has been minimized.

@jasnell

jasnell Sep 25, 2017

Member

This should likely be ERR_INVALID_OPTION_VALUE

@jasnell

jasnell Sep 25, 2017

Member

This should likely be ERR_INVALID_OPTION_VALUE

This comment has been minimized.

@pmatzavin

pmatzavin Sep 28, 2017

Contributor

There are thrown errors for all the following 4 values in lib/net lookupAndConnect function :

function lookupAndConnect(self, options) {
  // ...
  options.port
  options.localAddress
   options.localPort
  options.lookup
  // ...

So I guess that for consistency, all the errors thrown for invalid values of the above vars should have a code of ERR_INVALID_OPTION_VALUE

@pmatzavin

pmatzavin Sep 28, 2017

Contributor

There are thrown errors for all the following 4 values in lib/net lookupAndConnect function :

function lookupAndConnect(self, options) {
  // ...
  options.port
  options.localAddress
   options.localPort
  options.lookup
  // ...

So I guess that for consistency, all the errors thrown for invalid values of the above vars should have a code of ERR_INVALID_OPTION_VALUE

This comment has been minimized.

@BridgeAR

BridgeAR Oct 2, 2017

Member

I checked how we use mainly use this right now in the code base and it seems like ERR_INVALID_ARG_TYPE is the right type here. We might improve those types in general later on further but I think this should not block the PR from being merged.

@BridgeAR

BridgeAR Oct 2, 2017

Member

I checked how we use mainly use this right now in the code base and it seems like ERR_INVALID_ARG_TYPE is the right type here. We might improve those types in general later on further but I think this should not block the PR from being merged.

@jasnell

This comment has been minimized.

Show comment
Hide comment
Member

jasnell commented Sep 25, 2017

@pmatzavin

This comment has been minimized.

Show comment
Hide comment
@pmatzavin

pmatzavin Sep 26, 2017

Contributor

Sry for being unresponsive. I was unavailable due to some hlth problem. I will look into the issues.

Contributor

pmatzavin commented Sep 26, 2017

Sry for being unresponsive. I was unavailable due to some hlth problem. I will look into the issues.

@jasnell

This comment has been minimized.

Show comment
Hide comment
@jasnell

jasnell Sep 26, 2017

Member

@pmatzavin ... no worries. Hope you're feeling better.

Member

jasnell commented Sep 26, 2017

@pmatzavin ... no worries. Hope you're feeling better.

@pmatzavin

This comment has been minimized.

Show comment
Hide comment
@pmatzavin

pmatzavin Sep 27, 2017

Contributor

I am getting different results when running the tests locally. The CI failing test(parallel/test-net-socket-fd-error) passes in my local env. I haven't found yet, why this can be inconsistent.
I double-checked that I have the correct source-code (after the rebase)

Contributor

pmatzavin commented Sep 27, 2017

I am getting different results when running the tests locally. The CI failing test(parallel/test-net-socket-fd-error) passes in my local env. I haven't found yet, why this can be inconsistent.
I double-checked that I have the correct source-code (after the rebase)

[fixup] lib/net: remove failing test
removed the
test/parallel/test-net-socket-fd-error.js

this test was added in the current PR
but is not consistent. As the used
fd mock value does not consistenly
resolve to a fd type not equal to 'PIPE'
and not equal to 'TCP'
@pmatzavin

This comment has been minimized.

Show comment
Hide comment
@pmatzavin

pmatzavin Sep 27, 2017

Contributor

I removed the failing test / file:
test/parallel/test-net-socket-fd-error.js

This test was added by me in the current PR
but is not consistent. As the used
fd mock value does not consistently
resolve to a fd type not equal to 'PIPE'
and not equal to 'TCP'. The test was trying to assert the err in:

/* lib/net.js */
function createHandle(fd) {
  const type = TTYWrap.guessHandleType(fd);
  if (type === 'PIPE') return new Pipe();
  if (type === 'TCP') return new TCP();
  throw new errors.TypeError('ERR_INVALID_FD_TYPE', type);
}

by calling

new net.Socket({
 fd: 'invalid'
});

but i could not find a fd value/number that will fit for this test.

Contributor

pmatzavin commented Sep 27, 2017

I removed the failing test / file:
test/parallel/test-net-socket-fd-error.js

This test was added by me in the current PR
but is not consistent. As the used
fd mock value does not consistently
resolve to a fd type not equal to 'PIPE'
and not equal to 'TCP'. The test was trying to assert the err in:

/* lib/net.js */
function createHandle(fd) {
  const type = TTYWrap.guessHandleType(fd);
  if (type === 'PIPE') return new Pipe();
  if (type === 'TCP') return new TCP();
  throw new errors.TypeError('ERR_INVALID_FD_TYPE', type);
}

by calling

new net.Socket({
 fd: 'invalid'
});

but i could not find a fd value/number that will fit for this test.

@BridgeAR

This comment has been minimized.

Show comment
Hide comment
@BridgeAR

BridgeAR Sep 27, 2017

Member

@pmatzavin I think only one review has to be addressed and it should be good to go. I will start a CI as soon as that is done.

Member

BridgeAR commented Sep 27, 2017

@pmatzavin I think only one review has to be addressed and it should be good to go. I will start a CI as soon as that is done.

@BridgeAR

This comment has been minimized.

Show comment
Hide comment
@BridgeAR

This comment has been minimized.

Show comment
Hide comment
@BridgeAR
Member

BridgeAR commented Oct 2, 2017

@joyeecheung

This comment has been minimized.

Show comment
Hide comment
@joyeecheung
Member

joyeecheung commented Oct 14, 2017

@joyeecheung

This comment has been minimized.

Show comment
Hide comment
@joyeecheung

joyeecheung Oct 15, 2017

Member

Landed in 7f55349

Note that there is still #15589 that we need to fix after this (See #14782 (review) regarding using ERR_INVALID_OPT_VALUE v.s. ERR_INVALID_ARG_TYPE v.s. a new error for the overloaded server.listen()). IMO We should not release this PR until that gets resolved.

Member

joyeecheung commented Oct 15, 2017

Landed in 7f55349

Note that there is still #15589 that we need to fix after this (See #14782 (review) regarding using ERR_INVALID_OPT_VALUE v.s. ERR_INVALID_ARG_TYPE v.s. a new error for the overloaded server.listen()). IMO We should not release this PR until that gets resolved.

joyeecheung added a commit that referenced this pull request Oct 15, 2017

net: convert to using internal/errors
Covert lib/net.js over to using lib/internal/errors.js

- Replace thrown errors in lib/net.js
  with errors from lib/internal/errors.
  The ERR_INVALID_OPT_VALUE error have been used
  in the Server.prototype.listen() method
- Update tests according to the above modifications

PR-URL: #14782
Refs: #11273
Reviewed-By: Refael Ackermann <refack@gmail.com>
Reviewed-By: James M Snell <jasnell@gmail.com>
Reviewed-By: Ruben Bridgewater <ruben@bridgewater.de>
Reviewed-By: Michael Dawson <michael_dawson@ca.ibm.com>
Reviewed-By: Joyee Cheung <joyeec9h3@gmail.com>

addaleax added a commit to ayojs/ayo that referenced this pull request Oct 15, 2017

net: convert to using internal/errors
Covert lib/net.js over to using lib/internal/errors.js

- Replace thrown errors in lib/net.js
  with errors from lib/internal/errors.
  The ERR_INVALID_OPT_VALUE error have been used
  in the Server.prototype.listen() method
- Update tests according to the above modifications

PR-URL: nodejs/node#14782
Refs: nodejs/node#11273
Reviewed-By: Refael Ackermann <refack@gmail.com>
Reviewed-By: James M Snell <jasnell@gmail.com>
Reviewed-By: Ruben Bridgewater <ruben@bridgewater.de>
Reviewed-By: Michael Dawson <michael_dawson@ca.ibm.com>
Reviewed-By: Joyee Cheung <joyeec9h3@gmail.com>

@jasnell jasnell moved this from In Progress to Done in Error Codes Oct 25, 2017

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment