Skip to content

Commit 7f8834f

Browse files
jasnellMylesBorins
authored andcommitted
src: more idiomatic error pattern in node_wasi
Signed-off-by: James M Snell <[email protected]> PR-URL: #35493 Reviewed-By: Daijiro Wachi <[email protected]> Reviewed-By: Tobias Nießen <[email protected]> Reviewed-By: David Carlier <[email protected]> Reviewed-By: Anna Henningsen <[email protected]> Reviewed-By: Rich Trott <[email protected]>
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)