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

dgram: convert to using internal/errors #12926

Closed
wants to merge 1 commit into from

Conversation

mhdawson
Copy link
Member

@mhdawson mhdawson commented May 9, 2017

Convert lib/dgram.js over to using lib/internal/errors.js
for generating Errors. See using-internal-errors.md for more details.

I have not addressed the cases that use errnoException() and
exceptionWithHostPort() helper methods as changing these would require
fixing the tests across all of the different files that use them. In
addition, these helpers already add a code to the Error and we'll
have to discuss how that interacts with the code used by
lib/internal/errors.js. I believe we should convert all users
of errnoException and exceptionWithHostPort in a PR dedicated to
that conversion.

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)

dgram

@nodejs-github-bot nodejs-github-bot added dgram Issues and PRs related to the dgram subsystem / UDP. errors Issues and PRs related to JavaScript errors originated in Node.js core. labels May 9, 2017
@mhdawson mhdawson requested a review from jasnell May 9, 2017 18:32
@thefourtheye
Copy link
Contributor

It shows there is a merge conflict in doc/api/errors.md

lib/dgram.js Outdated
if (typeof offset !== 'number' || typeof length !== 'number')
throw new Error('Send takes "offset" and "length" as args 2 and 3');
if (typeof offset !== 'number') {
throw new errors.Error('ERR_INVALID_ARG_TYPE', 'offset', 'number');
Copy link
Member

Choose a reason for hiding this comment

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

That should probably be a TypeError as well as the other errors thrown in the sendTo function.

Copy link
Member Author

@mhdawson mhdawson May 9, 2017

Choose a reason for hiding this comment

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

I held off changing the types of errors as that may be more breaking than just changing the message. @jasnell what's your take on that front ?

Copy link
Member

Choose a reason for hiding this comment

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

I would go ahead and change the type as appropriate. It's already a breaking change, we might as well rip the bandaid off all at once.

Copy link
Member Author

Choose a reason for hiding this comment

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

ok will change

@mhdawson mhdawson added the semver-major PRs that contain breaking changes and should be released in the next major version. label May 9, 2017
@mhdawson
Copy link
Member Author

mhdawson commented May 9, 2017

@thefourtheye thanks for pointing that out, rebased.

lib/dgram.js Outdated
'string or falsy');
throw new errors.TypeError('ERR_INVALID_ARG_TYPE',
'address',
'string or falsy');
Copy link
Member

Choose a reason for hiding this comment

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

this can be passed in as ['string', 'falsy']

Copy link
Member Author

Choose a reason for hiding this comment

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

will update

@mhdawson
Copy link
Member Author

mhdawson commented May 9, 2017

@jasnell, @BridgeAR pushed commit to address comments.

lib/dgram.js Outdated
@@ -543,7 +563,7 @@ Socket.prototype.addMembership = function(multicastAddress,
this._healthCheck();

if (!multicastAddress) {
throw new Error('multicast address must be specified');
throw new errors.Error('ERR_MISSING_ARGS', 'multicastAaddress');
Copy link
Member

Choose a reason for hiding this comment

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

This should be a TypeError.

Copy link
Member

Choose a reason for hiding this comment

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

This should be a TypeError.

My immediate reaction was to disagree on the grounds that aTypeError means an argument is the wrong type, not missing.

But TypeError is what V8 uses for similar situations, so I'm inclined to agree that Node.js should do the same.

> [0,1,2].forEach()
TypeError: undefined is not a function
 ...
>

Copy link
Member Author

Choose a reason for hiding this comment

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

I think as long as we are consistent across the board, then I'm ok based on the example set by v8

Copy link
Member Author

Choose a reason for hiding this comment

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

Seems like we already use TypeError in other tests in this case as well. So TypeError is the way to go.

Copy link
Member Author

Choose a reason for hiding this comment

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

Will Fix.

Copy link
Member Author

Choose a reason for hiding this comment

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

@Trott fixed.

lib/dgram.js Outdated
@@ -558,7 +578,7 @@ Socket.prototype.dropMembership = function(multicastAddress,
this._healthCheck();

if (!multicastAddress) {
throw new Error('multicast address must be specified');
throw new errors.Error('ERR_MISSING_ARGS', 'multicastAaddress');
Copy link
Member

Choose a reason for hiding this comment

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

This should be a TypeError.

Copy link
Member Author

Choose a reason for hiding this comment

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

Will Fix.

@mhdawson
Copy link
Member Author

@BridgeAR thanks for catching those additional TypeErrors, pushed commit to address comment.

@mhdawson
Copy link
Member Author

@jasnell all comments so far should be addressed.

@mhdawson
Copy link
Member Author

@nodejs/ctc I believe I need a second CTC reviewer since this is semver major.

@mhdawson
Copy link
Member Author

@thefourtheye any chance you can take another look ?

lib/dgram.js Outdated
@@ -543,7 +563,7 @@ Socket.prototype.addMembership = function(multicastAddress,
this._healthCheck();

if (!multicastAddress) {
throw new Error('multicast address must be specified');
throw new errors.TypeError('ERR_MISSING_ARGS', 'multicastAaddress');
Copy link
Member

@fhinkel fhinkel May 23, 2017

Choose a reason for hiding this comment

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

Typo in multicastAddress.

lib/dgram.js Outdated
@@ -558,7 +578,7 @@ Socket.prototype.dropMembership = function(multicastAddress,
this._healthCheck();

if (!multicastAddress) {
throw new Error('multicast address must be specified');
throw new errors.TypeError('ERR_MISSING_ARGS', 'multicastAaddress');
Copy link
Member

Choose a reason for hiding this comment

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

Same typo.

lib/dgram.js Outdated
if (!this._handle)
throw new Error('Not running'); // error message from dgram_legacy.js
if (!this._handle) {
// error message from dgram_legacy.js
Copy link
Member

Choose a reason for hiding this comment

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

Are we usually starting all comments with a capital letter and . at the end?

}, common.expectsError({
code: 'ERR_MISSING_ARGS',
type: TypeError,
message: /^The "multicastAaddress" argument must be specified$/
Copy link
Member

Choose a reason for hiding this comment

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

Typo in Aaddress.

}, common.expectsError({
code: 'ERR_MISSING_ARGS',
type: TypeError,
message: /^The "multicastAaddress" argument must be specified$/
Copy link
Member

@fhinkel fhinkel May 23, 2017

Choose a reason for hiding this comment

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

One more 😉

Copy link
Member

@fhinkel fhinkel left a comment

Choose a reason for hiding this comment

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

LGTM with the Aaddress typo. Thanks!

@mhdawson
Copy link
Member Author

@fhinkel thanks for the review. Will fix those up today.

@mhdawson
Copy link
Member Author

@fhinkel pushed commit to address comments. Do you think I should go ahead and land this or wait for the other older PRs to land first. There are sure to be conflicts between them.

@fhinkel
Copy link
Member

fhinkel commented May 23, 2017

Go ahead and land. We'll rebase the older PRs accordingly.

@mhdawson
Copy link
Member Author

@mhdawson
Copy link
Member Author

mhdawson commented May 23, 2017

See there are already conflicts. Will fix those up.

Covert lib/dgram.js over to using lib/internal/errors.js
for generating Errors. See
[using-internal-errors.md](https://github.com/nodejs/node/blob/master/doc/guides/using-internal-errors.md)
for more details.

I have not addressed the cases that use errnoException() and
exceptionWithHostPort() helper methods as changing these would require
fixing the tests across all of the different files that use them. In
addition, these helpers already add a `code` to the Error and we'll
have to discuss how that interacts with the `code` used by
lib/internal/errors.js.  I believe we should convert all users
of errnoException and exceptionWithHostPort in a PR dedicated to
that conversion.
@mhdawson
Copy link
Member Author

rebased and squashed commit for comments.

@mhdawson
Copy link
Member Author

@mhdawson
Copy link
Member Author

Landed as e912c67

@mhdawson mhdawson closed this May 24, 2017
mhdawson added a commit that referenced this pull request May 24, 2017
Covert lib/dgram.js over to using lib/internal/errors.js
for generating Errors. See
[using-internal-errors.md](https://github.com/nodejs/node/blob/master/doc/guides/using-internal-errors.md)
for more details.

I have not addressed the cases that use errnoException() and
exceptionWithHostPort() helper methods as changing these would require
fixing the tests across all of the different files that use them. In
addition, these helpers already add a `code` to the Error and we'll
have to discuss how that interacts with the `code` used by
lib/internal/errors.js.  I believe we should convert all users
of errnoException and exceptionWithHostPort in a PR dedicated to
that conversion.

PR-URL: #12926
Reviewed-By: James M Snell <jasnell@gmail.com>
Reviewed-By: Franziska Hinkelmann <franziska.hinkelmann@gmail.com>
Reviewed-By: Ruben Bridgewater <ruben.bridgewater@fintura.de>
jasnell pushed a commit that referenced this pull request May 24, 2017
Covert lib/dgram.js over to using lib/internal/errors.js
for generating Errors. See
[using-internal-errors.md](https://github.com/nodejs/node/blob/master/doc/guides/using-internal-errors.md)
for more details.

I have not addressed the cases that use errnoException() and
exceptionWithHostPort() helper methods as changing these would require
fixing the tests across all of the different files that use them. In
addition, these helpers already add a `code` to the Error and we'll
have to discuss how that interacts with the `code` used by
lib/internal/errors.js.  I believe we should convert all users
of errnoException and exceptionWithHostPort in a PR dedicated to
that conversion.

PR-URL: #12926
Reviewed-By: James M Snell <jasnell@gmail.com>
Reviewed-By: Franziska Hinkelmann <franziska.hinkelmann@gmail.com>
Reviewed-By: Ruben Bridgewater <ruben.bridgewater@fintura.de>
jasnell pushed a commit that referenced this pull request May 28, 2017
Covert lib/dgram.js over to using lib/internal/errors.js
for generating Errors. See
[using-internal-errors.md](https://github.com/nodejs/node/blob/master/doc/guides/using-internal-errors.md)
for more details.

I have not addressed the cases that use errnoException() and
exceptionWithHostPort() helper methods as changing these would require
fixing the tests across all of the different files that use them. In
addition, these helpers already add a `code` to the Error and we'll
have to discuss how that interacts with the `code` used by
lib/internal/errors.js.  I believe we should convert all users
of errnoException and exceptionWithHostPort in a PR dedicated to
that conversion.

PR-URL: #12926
Reviewed-By: James M Snell <jasnell@gmail.com>
Reviewed-By: Franziska Hinkelmann <franziska.hinkelmann@gmail.com>
Reviewed-By: Ruben Bridgewater <ruben.bridgewater@fintura.de>
@jasnell jasnell mentioned this pull request May 28, 2017
@mhdawson mhdawson deleted the messages1 branch June 28, 2017 19:23
refack pushed a commit to pmatzavin/node that referenced this pull request Aug 31, 2017
covert lib/fs.js over to using lib/internal/errors.js
i have not addressed the cases that use errnoException(),
for reasons described in nodejsGH-12926

- throw the ERR_INVALID_CALLBACK error
  when the the callback is invalid
- replace the ['object', 'string'] with
  ['string', 'object'] in the error constructor call,
  to better match the previous err msg
  in the getOptions() function
- add error ERR_VALUE_OUT_OF_RANGE in lib/internal/errors.js,
  this error is thrown when a numeric value is out of range
- document the ERR_VALUE_OUT_OF_RANGE err in errors.md
- correct the expected args, in the error thrown in the function
  fs._toUnixTimestamp() to ['Date', 'time in seconds'] (lib/fs.js)
- update the listener error type in the fs.watchFile() function,
  from Error to TypeError (lib/fs.js)
- update errors from ERR_INVALID_OPT_VALUE to ERR_INVALID_ARG_TYPE
  in the functions fs.ReadStream() and fs.WriteStream(),
  for the cases of range errors use the new error:
  ERR_VALUE_OUT_OF_RANGE (lib/fs.js)

PR-URL: nodejs#15043
Refs: nodejs#11273
Reviewed-By: Refael Ackermann <refack@gmail.com>
Reviewed-By: James M Snell <jasnell@gmail.com>
Reviewed-By: Michael Dawson <michael_dawson@ca.ibm.com>
refack pushed a commit to refack/node that referenced this pull request Aug 31, 2017
covert lib/fs.js over to using lib/internal/errors.js
i have not addressed the cases that use errnoException(),
for reasons described in nodejsGH-12926

- throw the ERR_INVALID_CALLBACK error
  when the the callback is invalid
- replace the ['object', 'string'] with
  ['string', 'object'] in the error constructor call,
  to better match the previous err msg
  in the getOptions() function
- add error ERR_VALUE_OUT_OF_RANGE in lib/internal/errors.js,
  this error is thrown when a numeric value is out of range
- document the ERR_VALUE_OUT_OF_RANGE err in errors.md
- correct the expected args, in the error thrown in the function
  fs._toUnixTimestamp() to ['Date', 'time in seconds'] (lib/fs.js)
- update the listener error type in the fs.watchFile() function,
  from Error to TypeError (lib/fs.js)
- update errors from ERR_INVALID_OPT_VALUE to ERR_INVALID_ARG_TYPE
  in the functions fs.ReadStream() and fs.WriteStream(),
  for the cases of range errors use the new error:
  ERR_VALUE_OUT_OF_RANGE (lib/fs.js)

PR-URL: nodejs#15043
Refs: nodejs#11273
Reviewed-By: Refael Ackermann <refack@gmail.com>
Reviewed-By: James M Snell <jasnell@gmail.com>
Reviewed-By: Michael Dawson <michael_dawson@ca.ibm.com>
addaleax pushed a commit to addaleax/node that referenced this pull request Sep 13, 2017
covert lib/fs.js over to using lib/internal/errors.js
i have not addressed the cases that use errnoException(),
for reasons described in nodejsGH-12926

- throw the ERR_INVALID_CALLBACK error
  when the the callback is invalid
- replace the ['object', 'string'] with
  ['string', 'object'] in the error constructor call,
  to better match the previous err msg
  in the getOptions() function
- add error ERR_VALUE_OUT_OF_RANGE in lib/internal/errors.js,
  this error is thrown when a numeric value is out of range
- document the ERR_VALUE_OUT_OF_RANGE err in errors.md
- correct the expected args, in the error thrown in the function
  fs._toUnixTimestamp() to ['Date', 'time in seconds'] (lib/fs.js)
- update the listener error type in the fs.watchFile() function,
  from Error to TypeError (lib/fs.js)
- update errors from ERR_INVALID_OPT_VALUE to ERR_INVALID_ARG_TYPE
  in the functions fs.ReadStream() and fs.WriteStream(),
  for the cases of range errors use the new error:
  ERR_VALUE_OUT_OF_RANGE (lib/fs.js)

PR-URL: nodejs#15043
Refs: nodejs#11273
Reviewed-By: Refael Ackermann <refack@gmail.com>
Reviewed-By: James M Snell <jasnell@gmail.com>
Reviewed-By: Michael Dawson <michael_dawson@ca.ibm.com>
jasnell pushed a commit to pmatzavin/node that referenced this pull request Sep 25, 2017
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
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
dgram Issues and PRs related to the dgram subsystem / UDP. errors Issues and PRs related to JavaScript errors originated in Node.js core. 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.

7 participants