@@ -835,7 +835,8 @@ MaybeLocal<Module> ResolveModuleCallback(Local<Context> context,
835
835
836
836
} // anonymous namespace
837
837
838
- MaybeLocal<Module> Shell::FetchModuleTree (Local<Context> context,
838
+ MaybeLocal<Module> Shell::FetchModuleTree (Local<Module> referrer,
839
+ Local<Context> context,
839
840
const std::string& file_name) {
840
841
DCHECK (IsAbsolutePath (file_name));
841
842
Isolate* isolate = context->GetIsolate ();
@@ -848,8 +849,16 @@ MaybeLocal<Module> Shell::FetchModuleTree(Local<Context> context,
848
849
source_text = ReadFile (isolate, fallback_file_name.c_str ());
849
850
}
850
851
}
852
+
853
+ ModuleEmbedderData* d = GetModuleDataFromContext (context);
851
854
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
+ }
853
862
Throw (isolate, msg.c_str ());
854
863
return MaybeLocal<Module>();
855
864
}
@@ -863,7 +872,6 @@ MaybeLocal<Module> Shell::FetchModuleTree(Local<Context> context,
863
872
return MaybeLocal<Module>();
864
873
}
865
874
866
- ModuleEmbedderData* d = GetModuleDataFromContext (context);
867
875
CHECK (d->specifier_to_module_map
868
876
.insert (std::make_pair (file_name, Global<Module>(isolate, module )))
869
877
.second );
@@ -878,7 +886,7 @@ MaybeLocal<Module> Shell::FetchModuleTree(Local<Context> context,
878
886
std::string absolute_path =
879
887
NormalizePath (ToSTLString (isolate, name), dir_name);
880
888
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 ()) {
882
890
return MaybeLocal<Module>();
883
891
}
884
892
}
@@ -1023,7 +1031,8 @@ void Shell::DoHostImportModuleDynamically(void* import_data) {
1023
1031
auto module_it = d->specifier_to_module_map .find (absolute_path);
1024
1032
if (module_it != d->specifier_to_module_map .end ()) {
1025
1033
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)) {
1027
1036
CHECK (try_catch.HasCaught ());
1028
1037
resolver->Reject (realm, try_catch.Exception ()).ToChecked ();
1029
1038
return ;
@@ -1090,7 +1099,8 @@ bool Shell::ExecuteModule(Isolate* isolate, const char* file_name) {
1090
1099
1091
1100
Local<Module> root_module;
1092
1101
1093
- if (!FetchModuleTree (realm, absolute_path).ToLocal (&root_module)) {
1102
+ if (!FetchModuleTree (Local<Module>(), realm, absolute_path)
1103
+ .ToLocal (&root_module)) {
1094
1104
CHECK (try_catch.HasCaught ());
1095
1105
ReportException (isolate, &try_catch);
1096
1106
return false ;
0 commit comments