-
Notifications
You must be signed in to change notification settings - Fork 30.2k
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
errors: add ERR_INVALID_OPT_TYPE and support options in validators.js #31251
Conversation
if (valueType !== undefined) { | ||
msg += `"${name}" ${valueType} `; |
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.
The only thing added to this function (along with the fourth argument), otherwise a copy of the ERR_INVALID_ARG_TYPE
function.
I actually forgot that |
It does of course not change the error code, so it's still a bit different. It would have probably been ideal to name the error I have to think about adding a completely new error code as implemented here. So far I have not made up my mind if I think it's good or bad. |
That's what I was thinking initially but considering the amount of ERR_INVALID_ARG_TYPE errors we already have decided that it was not worth it, the breakage is quite large for a 'generalization' change. Though I'd actually prefer this approach if we can make it. |
Context: #31178 (comment) |
This adds `ERR_INVALID_OPT_TYPE` error that is the equivalent of `ERR_INVALID_ARG_TYPE` for options.
`name` argument is now able to be and object with a `name` and `type` keys. If `type` is `'option'` then `ERR_INVALID_OPT_TYPE` and `ERR_INVALID_OPT_VALUE` errors will be used.
6cfb187
to
bd91796
Compare
For error related PRs? Not really |
Overall I am fine with having a separate error code for options types but changing the code for existing errors makes this a semver-major. |
@jasnell this doesn't change the existing error, the behavior should be exactly the same for |
So now we have |
@tniessen I agree that it's not the best solution, but that's what we already have (with The current idea is that if we know a more specific error (e.g. |
Pinging a few people based on |
8ae28ff
to
2935f72
Compare
I personally would keep it as is and I'm +-0 to this. What we do need is something to differentiate different error groups e.g., |
Not sure what the status is on this one but it needs a rebase |
I can rebase this if we decide to move on with this, unfortunately, there is not enough feedback. |
Will try moving in the other direction with this. |
This will be a start to generalize all argument validation errors. As currently we throw ARG/OPT, OUT_OF_RANGE, and other more specific errors. The OPT errors didn't bring much to the errors as it's just another variant of ARG error which is sometimes more confusing (some of our code used OPT errors to denote just argument validation errors presumably because of similarity of OPT to 'option' and not 'options-object') and they don't specify the name of the options object where the invalid value is located. Much better approach would be to just specify path to the invalid value in the name of the value as it is done in this PR (i.e. 'options.format', 'options.publicKey.type' etc) Also since this decreases a variety of errors we have it'd be easier to reuse validation code across the codebase. Refs: nodejs#31251 Refs: nodejs#34070 (comment) Signed-off-by: Denys Otrishko <shishugi@gmail.com>
This will be a start to generalize all argument validation errors. As currently we throw ARG/OPT, OUT_OF_RANGE, and other more specific errors. The OPT errors didn't bring much to the errors as it's just another variant of ARG error which is sometimes more confusing (some of our code used OPT errors to denote just argument validation errors presumably because of similarity of OPT to 'option' and not 'options-object') and they don't specify the name of the options object where the invalid value is located. Much better approach would be to just specify path to the invalid value in the name of the value as it is done in this PR (i.e. 'options.format', 'options.publicKey.type' etc) Also since this decreases a variety of errors we have it'd be easier to reuse validation code across the codebase. Refs: #31251 Refs: #34070 (comment) Signed-off-by: Denys Otrishko <shishugi@gmail.com> PR-URL: #34682 Reviewed-By: Matteo Collina <matteo.collina@gmail.com> Reviewed-By: Ruben Bridgewater <ruben@bridgewater.de> Reviewed-By: James M Snell <jasnell@gmail.com> Reviewed-By: Rich Trott <rtrott@gmail.com>
This will be a start to generalize all argument validation errors. As currently we throw ARG/OPT, OUT_OF_RANGE, and other more specific errors. The OPT errors didn't bring much to the errors as it's just another variant of ARG error which is sometimes more confusing (some of our code used OPT errors to denote just argument validation errors presumably because of similarity of OPT to 'option' and not 'options-object') and they don't specify the name of the options object where the invalid value is located. Much better approach would be to just specify path to the invalid value in the name of the value as it is done in this PR (i.e. 'options.format', 'options.publicKey.type' etc) Also since this decreases a variety of errors we have it'd be easier to reuse validation code across the codebase. Refs: nodejs#31251 Refs: nodejs#34070 (comment) Signed-off-by: Denys Otrishko <shishugi@gmail.com> PR-URL: nodejs#34682 Reviewed-By: Matteo Collina <matteo.collina@gmail.com> Reviewed-By: Ruben Bridgewater <ruben@bridgewater.de> Reviewed-By: James M Snell <jasnell@gmail.com> Reviewed-By: Rich Trott <rtrott@gmail.com>
Description in the commit messages.
Also, I considered adding helper functions like
validateBufferOpt
to avoid having to write an object withtype: 'option'
every time, WDYT?Checklist
make -j4 test
(UNIX), orvcbuild test
(Windows) passes/cc @BridgeAR