lib/net: Convert to using internal/errors by pmatzavin · Pull Request #14782 · nodejs/node

@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 12, 2017

Trott

Trott previously requested changes Aug 12, 2017

@refack refack added the semver-major

PRs that contain breaking changes and should be released in the next major version.

label

Aug 12, 2017

jasnell

jasnell

jasnell

maclover7

BridgeAR

BridgeAR

BridgeAR

BridgeAR

matzavinos added 9 commits

September 25, 2017 15:19
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
- 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
- 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
replace "listen options" with "options"
- 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.
- 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
- 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
- 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
- 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

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'

joyeecheung pushed a commit that referenced this pull request

Oct 15, 2017
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 pushed a commit to ayojs/ayo that referenced this pull request

Oct 15, 2017
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>