-
Notifications
You must be signed in to change notification settings - Fork 30k
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
Conversation
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'); |
There was a problem hiding this comment.
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.
There was a problem hiding this comment.
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 ?
There was a problem hiding this comment.
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.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
ok will change
@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'); |
There was a problem hiding this comment.
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']
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
will update
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'); |
There was a problem hiding this comment.
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
.
There was a problem hiding this comment.
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
...
>
There was a problem hiding this comment.
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
There was a problem hiding this comment.
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.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Will Fix.
There was a problem hiding this comment.
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'); |
There was a problem hiding this comment.
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
.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Will Fix.
@BridgeAR thanks for catching those additional TypeErrors, pushed commit to address comment. |
@jasnell all comments so far should be addressed. |
@nodejs/ctc I believe I need a second CTC reviewer since this is semver major. |
@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'); |
There was a problem hiding this comment.
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'); |
There was a problem hiding this comment.
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 |
There was a problem hiding this comment.
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$/ |
There was a problem hiding this comment.
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$/ |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
One more 😉
There was a problem hiding this 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!
@fhinkel thanks for the review. Will fix those up today. |
@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. |
Go ahead and land. We'll rebase the older PRs accordingly. |
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.
rebased and squashed commit for comments. |
Landed as e912c67 |
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>
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>
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>
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>
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>
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>
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
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'llhave to discuss how that interacts with the
code
used bylib/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), orvcbuild test
(Windows) passesAffected core subsystem(s)
dgram