Skip to content

Commit 8beef5e

Browse files
jasnellTrott
authored andcommitted
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 530acd1 commit 8beef5e

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
@@ -104,9 +104,9 @@ static MaybeLocal<Value> WASIException(Local<Context> context,
104104
js_msg =
105105
String::Concat(isolate, js_msg, FIXED_ONE_BYTE_STRING(isolate, ", "));
106106
js_msg = String::Concat(isolate, js_msg, js_syscall);
107-
Local<Object> e =
108-
Exception::Error(js_msg)->ToObject(context)
109-
.ToLocalChecked();
107+
Local<Object> e;
108+
if (!Exception::Error(js_msg)->ToObject(context).ToLocal(&e))
109+
return MaybeLocal<Value>();
110110

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

137-
context->GetIsolate()->ThrowException(exception.ToLocalChecked());
135+
env->isolate()->ThrowException(exception);
138136
}
139137
}
140138

0 commit comments

Comments
 (0)