Skip to content

Commit

Permalink
src: more idiomatic error pattern in node_wasi
Browse files Browse the repository at this point in the history
Signed-off-by: James M Snell <jasnell@gmail.com>

PR-URL: nodejs#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>
  • Loading branch information
jasnell authored and joesepi committed Oct 22, 2020
1 parent fbf5b39 commit 94b2530
Showing 1 changed file with 6 additions and 8 deletions.
14 changes: 6 additions & 8 deletions src/node_wasi.cc
Original file line number Diff line number Diff line change
Expand Up @@ -104,9 +104,9 @@ static MaybeLocal<Value> WASIException(Local<Context> context,
js_msg =
String::Concat(isolate, js_msg, FIXED_ONE_BYTE_STRING(isolate, ", "));
js_msg = String::Concat(isolate, js_msg, js_syscall);
Local<Object> e =
Exception::Error(js_msg)->ToObject(context)
.ToLocalChecked();
Local<Object> e;
if (!Exception::Error(js_msg)->ToObject(context).ToLocal(&e))
return MaybeLocal<Value>();

if (e->Set(context,
env->errno_string(),
Expand All @@ -128,13 +128,11 @@ WASI::WASI(Environment* env,
options->allocator = &alloc_info_;
int err = uvwasi_init(&uvw_, options);
if (err != UVWASI_ESUCCESS) {
Local<Context> context = env->context();
MaybeLocal<Value> exception = WASIException(context, err, "uvwasi_init");

if (exception.IsEmpty())
Local<Value> exception;
if (!WASIException(env->context(), err, "uvwasi_init").ToLocal(&exception))
return;

context->GetIsolate()->ThrowException(exception.ToLocalChecked());
env->isolate()->ThrowException(exception);
}
}

Expand Down

0 comments on commit 94b2530

Please sign in to comment.