-
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: add error code helpers to env #19465
Conversation
I have left out some argument checking errors in node_crypto.cc and node.cc since I believe when they are converted into JS land they will have different errors thrown anyway - for example, a lot of ERR_MISSING_ARGS are usually just replaced by individual ERR_INVALID_ARG_TYPE, and we usually just ignore the extra arguments instead of throwing an error. |
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.
changes look good overall. i'm a bit curious how many of these can be removed (e.g. the constructor check in ModuleWrap::Resolve seems unneeded) or moved to js
<a id="ERR_INVALID_CONSTRUCTOR_CALL"></a> | ||
### ERR_INVALID_CONSTRUCTOR_CALL | ||
|
||
A function that should not be invoked as a construcor was invoked with `new` |
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.
construcor -> constructor
src/inspector_js_api.cc
Outdated
@@ -96,7 +97,7 @@ class JSBindingsConnection : public AsyncWrap { | |||
static void New(const FunctionCallbackInfo<Value>& info) { | |||
Environment* env = Environment::GetCurrent(info); | |||
if (!info[0]->IsFunction()) { | |||
env->ThrowTypeError("Message callback is required"); | |||
env->THROW_ERR_INVALID_CALLBACK("Message callback is required"); |
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.
These should really use standard messages that could be specified in the macro definitions... e.g. this should be env->THROW_ERR_INVALID_CALLBACK()
and use the same error message text as the javascript equivalent.
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.
@jasnell Yes, but this PR is more about assigning the codes in case we don't have the time to migrate them all before v10. Most of the errors touched here can be thrown in JS land anyway so I've left most of the messages as-is since if we are going to change them, might as well just do it in JS. But if we don't manage to do a full migration to them all before v10 and don't even assign these codes in C++, then we'll have yet another bunch of semver-major error changes after v10. With this at least we should be free to improve the messages during v10.
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.
@jasnell I can leave these more obvious errors untouched if you think we can get them migrated properly before v10, the ones that I don't really think we'll have time to finish migrating to JS before v10 are the ones thrown in macros, like THROW_AND_RETURN_IF_OOB
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, that makes sense. I just wouldn't want it to fall off the radar... that is, I don't want folks to think that just because the code is assigned, there's nothing left to do on these.
This commit adds env->THROW_ERR_* and env->ERR_* helpers in the C++ land to quickly assign error codes to existing C++ errors. It also converts several errors in the C++ land that can be assigned either obvious existing error codes, or error codes close to existing ones. The plan is to first assign more error codes before v10, then either migrate the errors into JS land or improve the error messages during v10 without having to go semver-major since they already have error codes assigned. The following new error codes are added: - ERR_INVALID_CONSTRUCTOR_CALL - ERR_SCRIPT_EXECUTION_TIMEOUT (related to ERR_SCRIPT_EXECUTION_INTERRUPTED)
46acb2f
to
03a190f
Compare
@joyeecheung what is this blocked by at the moment? I think this is a good idea to get the codes in soon. It needs a rebase at the moment. |
Ping @joyeecheung |
Closed now that #20121 landed |
This commit adds env->THROW_ERR_* and env->ERR_* helpers in
the C++ land to quickly assign error codes to
existing C++ errors. It also converts several errors in the
C++ land that can be assigned either obvious existing error codes,
or error codes close to existing ones. The plan is to first
assign more error codes before v10, then either migrate the errors
into JS land or improve the error messages during v10 without
having to go semver-major since they already have error codes
assigned.
The following new error codes are added:
ERR_SCRIPT_EXECUTION_INTERRUPTED)
Checklist
make -j4 test
(UNIX), orvcbuild test
(Windows) passes