Skip to content
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: use proper errors as coming from StringBytes #14579

Closed
wants to merge 1 commit into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
60 changes: 12 additions & 48 deletions src/node_file.cc
Original file line number Diff line number Diff line change
Expand Up @@ -244,13 +244,7 @@ void After(uv_fs_t *req) {
req_wrap->encoding_,
&error);
if (link.IsEmpty()) {
// TODO(addaleax): Use `error` itself here.
argv[0] = UVException(env->isolate(),
UV_EINVAL,
req_wrap->syscall(),
"Invalid character encoding for filename",
req->path,
req_wrap->data());
argv[0] = error;
} else {
argv[1] = link.ToLocalChecked();
}
Expand All @@ -263,13 +257,7 @@ void After(uv_fs_t *req) {
req_wrap->encoding_,
&error);
if (link.IsEmpty()) {
// TODO(addaleax): Use `error` itself here.
argv[0] = UVException(env->isolate(),
UV_EINVAL,
req_wrap->syscall(),
"Invalid character encoding for link",
req->path,
req_wrap->data());
argv[0] = error;
} else {
argv[1] = link.ToLocalChecked();
}
Expand All @@ -281,13 +269,7 @@ void After(uv_fs_t *req) {
req_wrap->encoding_,
&error);
if (link.IsEmpty()) {
// TODO(addaleax): Use `error` itself here.
argv[0] = UVException(env->isolate(),
UV_EINVAL,
req_wrap->syscall(),
"Invalid character encoding for link",
req->path,
req_wrap->data());
argv[0] = error;
} else {
argv[1] = link.ToLocalChecked();
}
Expand Down Expand Up @@ -326,13 +308,7 @@ void After(uv_fs_t *req) {
req_wrap->encoding_,
&error);
if (filename.IsEmpty()) {
// TODO(addaleax): Use `error` itself here.
argv[0] = UVException(env->isolate(),
UV_EINVAL,
req_wrap->syscall(),
"Invalid character encoding for filename",
req->path,
req_wrap->data());
argv[0] = error;
break;
}
name_argv[name_idx++] = filename.ToLocalChecked();
Expand Down Expand Up @@ -711,11 +687,8 @@ static void ReadLink(const FunctionCallbackInfo<Value>& args) {
encoding,
&error);
if (rc.IsEmpty()) {
// TODO(addaleax): Use `error` itself here.
return env->ThrowUVException(UV_EINVAL,
"readlink",
"Invalid character encoding for link",
*path);
env->isolate()->ThrowException(error);
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

return env->isolate()->ThrowException(error);? The call to rc.ToLocalChecked() two lines down will fail if you fall through.

Same issue appears a few more times further down in this file.

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

done

return;
}
args.GetReturnValue().Set(rc.ToLocalChecked());
}
Expand Down Expand Up @@ -886,11 +859,8 @@ static void RealPath(const FunctionCallbackInfo<Value>& args) {
encoding,
&error);
if (rc.IsEmpty()) {
// TODO(addaleax): Use `error` itself here.
return env->ThrowUVException(UV_EINVAL,
"realpath",
"Invalid character encoding for path",
*path);
env->isolate()->ThrowException(error);
return;
}
args.GetReturnValue().Set(rc.ToLocalChecked());
}
Expand Down Expand Up @@ -940,11 +910,8 @@ static void ReadDir(const FunctionCallbackInfo<Value>& args) {
encoding,
&error);
if (filename.IsEmpty()) {
// TODO(addaleax): Use `error` itself here.
return env->ThrowUVException(UV_EINVAL,
"readdir",
"Invalid character encoding for filename",
*path);
env->isolate()->ThrowException(error);
return;
}

name_v[name_idx++] = filename.ToLocalChecked();
Expand Down Expand Up @@ -1405,11 +1372,8 @@ static void Mkdtemp(const FunctionCallbackInfo<Value>& args) {
MaybeLocal<Value> rc =
StringBytes::Encode(env->isolate(), path, encoding, &error);
if (rc.IsEmpty()) {
// TODO(addaleax): Use `error` itself here.
return env->ThrowUVException(UV_EINVAL,
"mkdtemp",
"Invalid character encoding for filename",
*tmpl);
env->isolate()->ThrowException(error);
return;
}
args.GetReturnValue().Set(rc.ToLocalChecked());
}
Expand Down
26 changes: 5 additions & 21 deletions src/node_os.cc
Original file line number Diff line number Diff line change
Expand Up @@ -376,27 +376,11 @@ static void GetUserInfo(const FunctionCallbackInfo<Value>& args) {
else
shell = StringBytes::Encode(env->isolate(), pwd.shell, encoding, &error);

uv_os_free_passwd(&pwd);

if (username.IsEmpty()) {
// TODO(addaleax): Use `error` itself here.
return env->ThrowUVException(UV_EINVAL,
"uv_os_get_passwd",
"Invalid character encoding for username");
}

if (homedir.IsEmpty()) {
// TODO(addaleax): Use `error` itself here.
return env->ThrowUVException(UV_EINVAL,
"uv_os_get_passwd",
"Invalid character encoding for homedir");
}

if (shell.IsEmpty()) {
// TODO(addaleax): Use `error` itself here.
return env->ThrowUVException(UV_EINVAL,
"uv_os_get_passwd",
"Invalid character encoding for shell");
if (username.IsEmpty() || homedir.IsEmpty() || shell.IsEmpty()) {
CHECK(!error.IsEmpty());
uv_os_free_passwd(&pwd);
env->isolate()->ThrowException(error);
return;
}

Local<Object> entry = Object::New(env->isolate());
Expand Down
2 changes: 0 additions & 2 deletions src/string_bytes.cc
Original file line number Diff line number Diff line change
Expand Up @@ -686,7 +686,6 @@ MaybeLocal<Value> StringBytes::Encode(Isolate* isolate,
CHECK_NE(encoding, UCS2);
CHECK_BUFLEN_IN_RANGE(buflen);

*error = Local<Value>();
if (!buflen && encoding != BUFFER) {
return String::Empty(isolate);
}
Expand Down Expand Up @@ -772,7 +771,6 @@ MaybeLocal<Value> StringBytes::Encode(Isolate* isolate,
size_t buflen,
Local<Value>* error) {
CHECK_BUFLEN_IN_RANGE(buflen);
*error = Local<Value>();

// Node's "ucs2" encoding expects LE character data inside a
// Buffer, so we need to reorder on BE platforms. See
Expand Down