diff options
author | Michaël Zasso <targos@protonmail.com> | 2017-12-20 10:42:24 +0100 |
---|---|---|
committer | Michaël Zasso <targos@protonmail.com> | 2017-12-24 17:38:36 +0100 |
commit | 359819e76052f456beeefeef9bed4062b6c9e7b0 (patch) | |
tree | d8529eb88ca98a9714ea159d97daa3906e24578b /src/module_wrap.cc | |
parent | d610fad39018a7f21904f2f8fa496c21472f05cb (diff) | |
download | android-node-v8-359819e76052f456beeefeef9bed4062b6c9e7b0.tar.gz android-node-v8-359819e76052f456beeefeef9bed4062b6c9e7b0.tar.bz2 android-node-v8-359819e76052f456beeefeef9bed4062b6c9e7b0.zip |
module: print better message on esm import error
Use the same approach as a previous PR to include the offending line in
the output and underline imports of inexistent exports.
PR-URL: https://github.com/nodejs/node/pull/17786
Fixes: https://github.com/nodejs/node/issues/17785
Refs: https://github.com/nodejs/node/pull/17281
Reviewed-By: Anna Henningsen <anna@addaleax.net>
Reviewed-By: Ben Noordhuis <info@bnoordhuis.nl>
Reviewed-By: Guy Bedford <guybedford@gmail.com>
Reviewed-By: Timothy Gu <timothygu99@gmail.com>
Reviewed-By: Colin Ihrig <cjihrig@gmail.com>
Reviewed-By: Jeremiah Senkpiel <fishrock123@rocketmail.com>
Reviewed-By: James M Snell <jasnell@gmail.com>
Diffstat (limited to 'src/module_wrap.cc')
-rw-r--r-- | src/module_wrap.cc | 8 |
1 files changed, 8 insertions, 0 deletions
diff --git a/src/module_wrap.cc b/src/module_wrap.cc index 2474b362d7..b8970d4fb3 100644 --- a/src/module_wrap.cc +++ b/src/module_wrap.cc @@ -179,6 +179,7 @@ void ModuleWrap::Link(const FunctionCallbackInfo<Value>& args) { } void ModuleWrap::Instantiate(const FunctionCallbackInfo<Value>& args) { + Environment* env = Environment::GetCurrent(args); Isolate* isolate = args.GetIsolate(); Local<Object> that = args.This(); Local<Context> context = that->CreationContext(); @@ -186,6 +187,7 @@ void ModuleWrap::Instantiate(const FunctionCallbackInfo<Value>& args) { ModuleWrap* obj = Unwrap<ModuleWrap>(that); CHECK_NE(obj, nullptr); Local<Module> module = obj->module_.Get(isolate); + TryCatch try_catch(isolate); Maybe<bool> ok = module->InstantiateModule(context, ModuleWrap::ResolveCallback); @@ -195,6 +197,12 @@ void ModuleWrap::Instantiate(const FunctionCallbackInfo<Value>& args) { obj->resolve_cache_.clear(); if (!ok.FromMaybe(false)) { + CHECK(try_catch.HasCaught()); + CHECK(!try_catch.Message().IsEmpty()); + CHECK(!try_catch.Exception().IsEmpty()); + AppendExceptionLine(env, try_catch.Exception(), try_catch.Message(), + ErrorHandlingMode::MODULE_ERROR); + try_catch.ReThrow(); return; } } |