-
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
src,lib: introduce util.getSystemErrorMessage(err)
#54075
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
util.getSystemErrorMessage(err)
This patch adds a new utility function which provides human-readable string description of the given system error code. Signed-off-by: Juan José Arboleda <[email protected]>
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -59,6 +59,15 @@ using v8::ReadOnly; | |
using v8::String; | ||
using v8::Value; | ||
|
||
void GetErrMessage(const FunctionCallbackInfo<Value>& args) { | ||
Environment* env = Environment::GetCurrent(args); | ||
int err = args[0].As<v8::Int32>()->Value(); | ||
CHECK_LT(err, 0); | ||
char message[50]; | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Why 50? Can you add a comment? There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Can you add a comment? |
||
uv_strerror_r(err, message, sizeof(message)); | ||
args.GetReturnValue().Set(OneByteString(env->isolate(), message)); | ||
} | ||
|
||
void ErrName(const FunctionCallbackInfo<Value>& args) { | ||
Environment* env = Environment::GetCurrent(args); | ||
if (env->options()->pending_deprecation && env->EmitErrNameWarning()) { | ||
|
@@ -70,8 +79,7 @@ void ErrName(const FunctionCallbackInfo<Value>& args) { | |
"DEP0119").IsNothing()) | ||
return; | ||
} | ||
int err; | ||
if (!args[0]->Int32Value(env->context()).To(&err)) return; | ||
int err = args[0].As<v8::Int32>()->Value(); | ||
CHECK_LT(err, 0); | ||
char name[50]; | ||
uv_err_name_r(err, name, sizeof(name)); | ||
|
@@ -128,11 +136,13 @@ void Initialize(Local<Object> target, | |
} | ||
|
||
SetMethod(context, target, "getErrorMap", GetErrMap); | ||
SetMethod(context, target, "getErrorMessage", GetErrMessage); | ||
} | ||
|
||
void RegisterExternalReferences(ExternalReferenceRegistry* registry) { | ||
registry->Register(ErrName); | ||
registry->Register(GetErrMap); | ||
registry->Register(GetErrMessage); | ||
} | ||
} // namespace uv | ||
} // namespace node | ||
|
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.
Why do we need to call validateNumber since in the next line we check for SafeNumber?
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 as name getter
https://github.com/juanarbol/node/blob/cf6d05950d991b0cbeb06aa10d5bcf79c485c81f/lib/util.js#L250
This more about the current codebase.