From 94b2530801d4345d64ea4951d154547516d5d9ba Mon Sep 17 00:00:00 2001 From: James M Snell Date: Sat, 3 Oct 2020 18:21:11 -0700 Subject: [PATCH] src: more idiomatic error pattern in node_wasi MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Signed-off-by: James M Snell PR-URL: https://github.com/nodejs/node/pull/35493 Reviewed-By: Daijiro Wachi Reviewed-By: Tobias Nießen Reviewed-By: David Carlier Reviewed-By: Anna Henningsen Reviewed-By: Rich Trott --- src/node_wasi.cc | 14 ++++++-------- 1 file changed, 6 insertions(+), 8 deletions(-) diff --git a/src/node_wasi.cc b/src/node_wasi.cc index 80182724afea9c..4dd534af4167ee 100644 --- a/src/node_wasi.cc +++ b/src/node_wasi.cc @@ -104,9 +104,9 @@ static MaybeLocal WASIException(Local context, js_msg = String::Concat(isolate, js_msg, FIXED_ONE_BYTE_STRING(isolate, ", ")); js_msg = String::Concat(isolate, js_msg, js_syscall); - Local e = - Exception::Error(js_msg)->ToObject(context) - .ToLocalChecked(); + Local e; + if (!Exception::Error(js_msg)->ToObject(context).ToLocal(&e)) + return MaybeLocal(); if (e->Set(context, env->errno_string(), @@ -128,13 +128,11 @@ WASI::WASI(Environment* env, options->allocator = &alloc_info_; int err = uvwasi_init(&uvw_, options); if (err != UVWASI_ESUCCESS) { - Local context = env->context(); - MaybeLocal exception = WASIException(context, err, "uvwasi_init"); - - if (exception.IsEmpty()) + Local exception; + if (!WASIException(env->context(), err, "uvwasi_init").ToLocal(&exception)) return; - context->GetIsolate()->ThrowException(exception.ToLocalChecked()); + env->isolate()->ThrowException(exception); } }