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: #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 MylesBorins committed Nov 16, 2020
1 parent ade27b7 commit 7f8834f
Showing 1 changed file with 6 additions and 8 deletions.
14 changes: 6 additions & 8 deletions src/node_wasi.cc
Expand Up @@ -103,9 +103,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 @@ -127,13 +127,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 7f8834f

Please sign in to comment.