Skip to content

Commit 7f8834f

Browse files
jasnellMylesBorins
authored andcommittedNov 16, 2020
src: more idiomatic error pattern in node_wasi
Signed-off-by: James M Snell <jasnell@gmail.com> PR-URL: #35493 Reviewed-By: Daijiro Wachi <daijiro.wachi@gmail.com> Reviewed-By: Tobias Nießen <tniessen@tnie.de> Reviewed-By: David Carlier <devnexen@gmail.com> Reviewed-By: Anna Henningsen <anna@addaleax.net> Reviewed-By: Rich Trott <rtrott@gmail.com>
1 parent ade27b7 commit 7f8834f

File tree

1 file changed

+6
-8
lines changed

1 file changed

+6
-8
lines changed
 

‎src/node_wasi.cc

+6-8
Original file line numberDiff line numberDiff line change
@@ -103,9 +103,9 @@ static MaybeLocal<Value> WASIException(Local<Context> context,
103103
js_msg =
104104
String::Concat(isolate, js_msg, FIXED_ONE_BYTE_STRING(isolate, ", "));
105105
js_msg = String::Concat(isolate, js_msg, js_syscall);
106-
Local<Object> e =
107-
Exception::Error(js_msg)->ToObject(context)
108-
.ToLocalChecked();
106+
Local<Object> e;
107+
if (!Exception::Error(js_msg)->ToObject(context).ToLocal(&e))
108+
return MaybeLocal<Value>();
109109

110110
if (e->Set(context,
111111
env->errno_string(),
@@ -127,13 +127,11 @@ WASI::WASI(Environment* env,
127127
options->allocator = &alloc_info_;
128128
int err = uvwasi_init(&uvw_, options);
129129
if (err != UVWASI_ESUCCESS) {
130-
Local<Context> context = env->context();
131-
MaybeLocal<Value> exception = WASIException(context, err, "uvwasi_init");
132-
133-
if (exception.IsEmpty())
130+
Local<Value> exception;
131+
if (!WASIException(env->context(), err, "uvwasi_init").ToLocal(&exception))
134132
return;
135133

136-
context->GetIsolate()->ThrowException(exception.ToLocalChecked());
134+
env->isolate()->ThrowException(exception);
137135
}
138136
}
139137

0 commit comments

Comments
 (0)
Please sign in to comment.