diff options
author | Gus Caplan <me@gus.host> | 2021-03-04 07:17:11 +0300 |
---|---|---|
committer | Gus Caplan <me@gus.host> | 2021-03-09 19:12:53 +0300 |
commit | 853086fbaa9ca7c698c891fe32a3a42c985e743d (patch) | |
tree | 337891dd642b7785dbefa8c7bab1af32136f4d11 /src/module_wrap.cc | |
parent | 16151bec081b55d8b2bb936f1f00207120a770db (diff) |
src: add error formatting support
PR-URL: https://github.com/nodejs/node/pull/37598
Reviewed-By: James M Snell <jasnell@gmail.com>
Reviewed-By: Anna Henningsen <anna@addaleax.net>
Reviewed-By: Darshan Sen <raisinten@gmail.com>
Reviewed-By: Michaƫl Zasso <targos@protonmail.com>
Diffstat (limited to 'src/module_wrap.cc')
-rw-r--r-- | src/module_wrap.cc | 24 |
1 files changed, 14 insertions, 10 deletions
diff --git a/src/module_wrap.cc b/src/module_wrap.cc index f4a7ad6b0c3..1fb2ea43307 100644 --- a/src/module_wrap.cc +++ b/src/module_wrap.cc @@ -297,7 +297,9 @@ void ModuleWrap::Link(const FunctionCallbackInfo<Value>& args) { Local<Value> resolve_return_value = maybe_resolve_return_value.ToLocalChecked(); if (!resolve_return_value->IsPromise()) { - env->ThrowError("linking error, expected resolver to return a promise"); + THROW_ERR_VM_MODULE_LINK_FAILURE( + env, "request for '%s' did not return promise", specifier_std); + return; } Local<Promise> resolve_promise = resolve_return_value.As<Promise>(); obj->resolve_cache_[specifier_std].Reset(env->isolate(), resolve_promise); @@ -497,17 +499,19 @@ MaybeLocal<Module> ModuleWrap::ResolveModuleCallback( Isolate* isolate = env->isolate(); + Utf8Value specifier_utf8(isolate, specifier); + std::string specifier_std(*specifier_utf8, specifier_utf8.length()); + ModuleWrap* dependent = GetFromModule(env, referrer); if (dependent == nullptr) { - env->ThrowError("linking error, null dep"); + THROW_ERR_VM_MODULE_LINK_FAILURE( + env, "request for '%s' is from invalid module", specifier_std); return MaybeLocal<Module>(); } - Utf8Value specifier_utf8(isolate, specifier); - std::string specifier_std(*specifier_utf8, specifier_utf8.length()); - if (dependent->resolve_cache_.count(specifier_std) != 1) { - env->ThrowError("linking error, not in local cache"); + THROW_ERR_VM_MODULE_LINK_FAILURE( + env, "request for '%s' is not in cache", specifier_std); return MaybeLocal<Module>(); } @@ -515,15 +519,15 @@ MaybeLocal<Module> ModuleWrap::ResolveModuleCallback( dependent->resolve_cache_[specifier_std].Get(isolate); if (resolve_promise->State() != Promise::kFulfilled) { - env->ThrowError("linking error, dependency promises must be resolved on " - "instantiate"); + THROW_ERR_VM_MODULE_LINK_FAILURE( + env, "request for '%s' is not yet fulfilled", specifier_std); return MaybeLocal<Module>(); } Local<Object> module_object = resolve_promise->Result().As<Object>(); if (module_object.IsEmpty() || !module_object->IsObject()) { - env->ThrowError("linking error, expected a valid module object from " - "resolver"); + THROW_ERR_VM_MODULE_LINK_FAILURE( + env, "request for '%s' did not return an object", specifier_std); return MaybeLocal<Module>(); } |