-
Notifications
You must be signed in to change notification settings - Fork 30.1k
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
src: assign error codes to more errors thrown in C++ #20121
Conversation
This patch migrates the "Index out of range" errors in C++ to errors with the code `ERR_INDEX_OUT_OF_RANGE` which have equivalents in JavaScript.
- Moves THROW_AND_RETURN_IF_NOT_BUFFER and THROW_AND_RETURN_IF_NOT_STRING from node_crypto.cc to node_errors.h so it can be reused. - Move THROW_AND_RETURN_UNLESS_BUFFER in util.h to node_buffer.cc and call THROW_AND_RETURN_IF_NOT_BUFFER there. The only other reference to THROW_AND_RETURN_UNLESS_BUFFER in node_i18n.cc can be safely replaced by an assertion since the argument will be checked in JS land. - Migrate ERR_INVALID_ARG_TYPE errors in C++. We can move the checks to JS land if possible later without having to go semver-major.
@@ -447,7 +448,7 @@ void Transcode(const FunctionCallbackInfo<Value>&args) { | |||
UErrorCode status = U_ZERO_ERROR; | |||
MaybeLocal<Object> result; | |||
|
|||
THROW_AND_RETURN_UNLESS_BUFFER(env, args[0]); | |||
CHECK(Buffer::HasInstance(args[0])); |
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 is replaced with a CHECK because the type is already checked in JS land
src/node_crypto.cc
Outdated
@@ -989,7 +976,8 @@ void SecureContext::SetOptions(const FunctionCallbackInfo<Value>& args) { | |||
ASSIGN_OR_RETURN_UNWRAP(&sc, args.Holder()); | |||
|
|||
if (args.Length() != 1 || !args[0]->IntegerValue()) { | |||
return sc->env()->ThrowTypeError("Options must be an integer value"); | |||
return node::THROW_ERR_INVALID_ARG_TYPE( |
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.
Perhaps remove the node
namespace here?
src/node_crypto.cc
Outdated
@@ -1043,8 +1031,8 @@ void SecureContext::SetSessionTimeout(const FunctionCallbackInfo<Value>& args) { | |||
ASSIGN_OR_RETURN_UNWRAP(&sc, args.Holder()); | |||
|
|||
if (args.Length() != 1 || !args[0]->IsInt32()) { | |||
return sc->env()->ThrowTypeError( | |||
"Session timeout must be a 32-bit integer"); | |||
return node::THROW_ERR_INVALID_ARG_TYPE( |
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.
Perhaps remove the node
namespace here?
src/node_crypto.cc
Outdated
@@ -4319,7 +4307,7 @@ void DiffieHellman::SetKey(const v8::FunctionCallbackInfo<v8::Value>& args, | |||
|
|||
if (!Buffer::HasInstance(args[0])) { | |||
snprintf(errmsg, sizeof(errmsg), "%s must be a buffer", what); | |||
return env->ThrowTypeError(errmsg); | |||
return node::THROW_ERR_INVALID_ARG_TYPE(env, errmsg); |
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.
Perhaps remove the node
namespace here?
CI failed due to infra failures, trying again...: https://ci.nodejs.org/job/node-test-commit/17848/ |
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
Just to have this written down: Since this is only changing type checking error messages and it’s extremely unlikely that they are being checked at all, and this will help making backports during the long v10.x lifecycle easier, I’m good with including this in v10.x as suggested by Joyee in the TSC meeting. I don’t think there were any objections from somebody else, either. |
@jasnell Can this go into v10 as is (with @danbev 's nits addressed) with some minor tweaks to error messages and types? They are just trivial errors (mostly type or range checking on arguments) so I do not think there will be users depending on those, IMO it makes sense to lift our current policy (any changes are semver-major) for this PR if it could not make it into v10.0.0. If not I can still try to backport this in a semver-minor manner, but it does not seem to be particularly worth the effort. |
CITGM, master: https://ci.nodejs.org/view/Node.js-citgm/job/citgm-smoker/1375/ |
I'm planning a release candidate build for 10.0.0 for tomorrow. If this lands by then and there are no objections from @nodejs/tsc, then I can pull this in to 10.0.0 assuming CITGM looks good. |
CITGM failures in #20121 (comment) look irrelavent. On master but not in PR:
On this PR but not on master:
|
Adding fast-track because of #20121 (comment) and in the TSC meeting where we had quorum no one objected to this landing on v10. |
Removed the |
One thing... this will need explicit @nodejs/tsc approval to fast track as a semver-major, otherwise there's no way it will land in time to make it in. After tomorrow I won't be pulling any semver-major's in at all unless there is explicit go ahead from the TSC (not just a no-objections, and explicit approval) |
@jasnell there was no objections to fast track in today's tsc meeting, in which there was quorum. Is that sufficient? |
Yep, so long as that's documented here that's perfect. :) |
The last CI seems clean, the only error seems to be related to #19903 |
Landed in 188ed07...fb58cae, thanks! |
PR-URL: #20121 Reviewed-By: Daniel Bevenius <[email protected]> Reviewed-By: Anna Henningsen <[email protected]> Reviewed-By: Matteo Collina <[email protected]> Reviewed-By: James M Snell <[email protected]> Reviewed-By: Jeremiah Senkpiel <[email protected]>
This patch migrates the "Index out of range" errors in C++ to errors with the code `ERR_INDEX_OUT_OF_RANGE` which have equivalents in JavaScript. PR-URL: #20121 Reviewed-By: Daniel Bevenius <[email protected]> Reviewed-By: Anna Henningsen <[email protected]> Reviewed-By: Matteo Collina <[email protected]> Reviewed-By: James M Snell <[email protected]> Reviewed-By: Jeremiah Senkpiel <[email protected]>
- Moves THROW_AND_RETURN_IF_NOT_BUFFER and THROW_AND_RETURN_IF_NOT_STRING from node_crypto.cc to node_errors.h so it can be reused. - Move THROW_AND_RETURN_UNLESS_BUFFER in util.h to node_buffer.cc and call THROW_AND_RETURN_IF_NOT_BUFFER there. The only other reference to THROW_AND_RETURN_UNLESS_BUFFER in node_i18n.cc can be safely replaced by an assertion since the argument will be checked in JS land. - Migrate ERR_INVALID_ARG_TYPE errors in C++. We can move the checks to JS land if possible later without having to go semver-major. PR-URL: #20121 Reviewed-By: Daniel Bevenius <[email protected]> Reviewed-By: Anna Henningsen <[email protected]> Reviewed-By: Matteo Collina <[email protected]> Reviewed-By: James M Snell <[email protected]> Reviewed-By: Jeremiah Senkpiel <[email protected]>
PR-URL: #20121 Reviewed-By: Daniel Bevenius <[email protected]> Reviewed-By: Anna Henningsen <[email protected]> Reviewed-By: Matteo Collina <[email protected]> Reviewed-By: James M Snell <[email protected]> Reviewed-By: Jeremiah Senkpiel <[email protected]>
PR-URL: #20121 Reviewed-By: Daniel Bevenius <[email protected]> Reviewed-By: Anna Henningsen <[email protected]> Reviewed-By: Matteo Collina <[email protected]> Reviewed-By: James M Snell <[email protected]> Reviewed-By: Jeremiah Senkpiel <[email protected]>
PR-URL: #20121 Reviewed-By: Daniel Bevenius <[email protected]> Reviewed-By: Anna Henningsen <[email protected]> Reviewed-By: Matteo Collina <[email protected]> Reviewed-By: James M Snell <[email protected]> Reviewed-By: Jeremiah Senkpiel <[email protected]>
PR-URL: #20121 Reviewed-By: Daniel Bevenius <[email protected]> Reviewed-By: Anna Henningsen <[email protected]> Reviewed-By: Matteo Collina <[email protected]> Reviewed-By: James M Snell <[email protected]> Reviewed-By: Jeremiah Senkpiel <[email protected]>
PR-URL: #20121 Reviewed-By: Daniel Bevenius <[email protected]> Reviewed-By: Anna Henningsen <[email protected]> Reviewed-By: Matteo Collina <[email protected]> Reviewed-By: James M Snell <[email protected]> Reviewed-By: Jeremiah Senkpiel <[email protected]>
This patch migrates the "Index out of range" errors in C++ to errors with the code `ERR_INDEX_OUT_OF_RANGE` which have equivalents in JavaScript. PR-URL: #20121 Reviewed-By: Daniel Bevenius <[email protected]> Reviewed-By: Anna Henningsen <[email protected]> Reviewed-By: Matteo Collina <[email protected]> Reviewed-By: James M Snell <[email protected]> Reviewed-By: Jeremiah Senkpiel <[email protected]>
- Moves THROW_AND_RETURN_IF_NOT_BUFFER and THROW_AND_RETURN_IF_NOT_STRING from node_crypto.cc to node_errors.h so it can be reused. - Move THROW_AND_RETURN_UNLESS_BUFFER in util.h to node_buffer.cc and call THROW_AND_RETURN_IF_NOT_BUFFER there. The only other reference to THROW_AND_RETURN_UNLESS_BUFFER in node_i18n.cc can be safely replaced by an assertion since the argument will be checked in JS land. - Migrate ERR_INVALID_ARG_TYPE errors in C++. We can move the checks to JS land if possible later without having to go semver-major. PR-URL: #20121 Reviewed-By: Daniel Bevenius <[email protected]> Reviewed-By: Anna Henningsen <[email protected]> Reviewed-By: Matteo Collina <[email protected]> Reviewed-By: James M Snell <[email protected]> Reviewed-By: Jeremiah Senkpiel <[email protected]>
PR-URL: #20121 Reviewed-By: Daniel Bevenius <[email protected]> Reviewed-By: Anna Henningsen <[email protected]> Reviewed-By: Matteo Collina <[email protected]> Reviewed-By: James M Snell <[email protected]> Reviewed-By: Jeremiah Senkpiel <[email protected]>
PR-URL: #20121 Reviewed-By: Daniel Bevenius <[email protected]> Reviewed-By: Anna Henningsen <[email protected]> Reviewed-By: Matteo Collina <[email protected]> Reviewed-By: James M Snell <[email protected]> Reviewed-By: Jeremiah Senkpiel <[email protected]>
PR-URL: #20121 Reviewed-By: Daniel Bevenius <[email protected]> Reviewed-By: Anna Henningsen <[email protected]> Reviewed-By: Matteo Collina <[email protected]> Reviewed-By: James M Snell <[email protected]> Reviewed-By: Jeremiah Senkpiel <[email protected]>
PR-URL: #20121 Reviewed-By: Daniel Bevenius <[email protected]> Reviewed-By: Anna Henningsen <[email protected]> Reviewed-By: Matteo Collina <[email protected]> Reviewed-By: James M Snell <[email protected]> Reviewed-By: Jeremiah Senkpiel <[email protected]>
This is a rework of #19465 , which tries to assign codes to more C++ errors first so we can change their messages later and do proper refactors without having to go semver-major.
Sorry that I don't have much time working on this recently so this might not be able to make it into v10, if that's the case I can try to make it semver-minor (only adding the code property without changing any error message or error types), or just do proper refactors and throw the errors in JS land instead - the ones thrown in macros would require significant work to be refactored properly though.
I have left out the
ERR_SCRIPT_EXECUTION_*
errors in #19465 because the new mechanism in #19739 use the Maybe version ofSet
and the returned Maybe is now empty when setting the code property there.I have also left out some errors related to the constructor or the
this
because I do not think that's what the errors we will eventually end up with, so there is no point adding them here and replacing them with something else later (like using the V8 signatures to check thethis
). Some errors in node_crypto.cc are left out because I think they will likely disappear when migrated properly later.There are no new error codes added this time around.
src: add THROW_ERR_* helpers
src: migrate ERR_INDEX_OUT_OF_RANGE in C++
This patch migrates the "Index out of range" errors in C++
to errors with the code
ERR_INDEX_OUT_OF_RANGE
which haveequivalents in JavaScript.
src: throw ERR_INVALID_ARG_TYPE in C++ argument checks
THROW_AND_RETURN_IF_NOT_STRING from node_crypto.cc to
node_errors.h so it can be reused.
node_buffer.cc and call THROW_AND_RETURN_IF_NOT_BUFFER
there. The only other reference to THROW_AND_RETURN_UNLESS_BUFFER in
node_i18n.cc can be safely replaced by an assertion since
the argument will be checked in JS land.
checks to JS land if possible later without having to
go semver-major.
src: throw ERR_BUFFER_OUT_OF_BOUNDS in node_buffer.cc
src: throw ERR_MISSING_MODULE in module_wrap.cc
src: throw ERR_INVALID_ARG_VALUE in node_crypto.cc
src: throw ERR_MISSING_ARGS in node_crypto.cc
Checklist
make -j4 test
(UNIX), orvcbuild test
(Windows) passes