@@ -835,7 +835,8 @@ MaybeLocal<Module> ResolveModuleCallback(Local<Context> context,
835835
836836} // anonymous namespace
837837
838- MaybeLocal<Module> Shell::FetchModuleTree (Local<Context> context,
838+ MaybeLocal<Module> Shell::FetchModuleTree (Local<Module> referrer,
839+ Local<Context> context,
839840 const std::string& file_name) {
840841 DCHECK (IsAbsolutePath (file_name));
841842 Isolate* isolate = context->GetIsolate ();
@@ -848,8 +849,16 @@ MaybeLocal<Module> Shell::FetchModuleTree(Local<Context> context,
848849 source_text = ReadFile (isolate, fallback_file_name.c_str ());
849850 }
850851 }
852+
853+ ModuleEmbedderData* d = GetModuleDataFromContext (context);
851854 if (source_text.IsEmpty ()) {
852- std::string msg = " d8: Error reading module from " + file_name;
855+ std::string msg = " d8: Error reading module from " + file_name;
856+ if (!referrer.IsEmpty ()) {
857+ auto specifier_it =
858+ d->module_to_specifier_map .find (Global<Module>(isolate, referrer));
859+ CHECK (specifier_it != d->module_to_specifier_map .end ());
860+ msg += " \n imported by " + specifier_it->second ;
861+ }
853862 Throw (isolate, msg.c_str ());
854863 return MaybeLocal<Module>();
855864 }
@@ -863,7 +872,6 @@ MaybeLocal<Module> Shell::FetchModuleTree(Local<Context> context,
863872 return MaybeLocal<Module>();
864873 }
865874
866- ModuleEmbedderData* d = GetModuleDataFromContext (context);
867875 CHECK (d->specifier_to_module_map
868876 .insert (std::make_pair (file_name, Global<Module>(isolate, module )))
869877 .second );
@@ -878,7 +886,7 @@ MaybeLocal<Module> Shell::FetchModuleTree(Local<Context> context,
878886 std::string absolute_path =
879887 NormalizePath (ToSTLString (isolate, name), dir_name);
880888 if (d->specifier_to_module_map .count (absolute_path)) continue ;
881- if (FetchModuleTree (context, absolute_path).IsEmpty ()) {
889+ if (FetchModuleTree (module , context, absolute_path).IsEmpty ()) {
882890 return MaybeLocal<Module>();
883891 }
884892 }
@@ -1023,7 +1031,8 @@ void Shell::DoHostImportModuleDynamically(void* import_data) {
10231031 auto module_it = d->specifier_to_module_map .find (absolute_path);
10241032 if (module_it != d->specifier_to_module_map .end ()) {
10251033 root_module = module_it->second .Get (isolate);
1026- } else if (!FetchModuleTree (realm, absolute_path).ToLocal (&root_module)) {
1034+ } else if (!FetchModuleTree (Local<Module>(), realm, absolute_path)
1035+ .ToLocal (&root_module)) {
10271036 CHECK (try_catch.HasCaught ());
10281037 resolver->Reject (realm, try_catch.Exception ()).ToChecked ();
10291038 return ;
@@ -1090,7 +1099,8 @@ bool Shell::ExecuteModule(Isolate* isolate, const char* file_name) {
10901099
10911100 Local<Module> root_module;
10921101
1093- if (!FetchModuleTree (realm, absolute_path).ToLocal (&root_module)) {
1102+ if (!FetchModuleTree (Local<Module>(), realm, absolute_path)
1103+ .ToLocal (&root_module)) {
10941104 CHECK (try_catch.HasCaught ());
10951105 ReportException (isolate, &try_catch);
10961106 return false ;
0 commit comments