Skip to content

Commit

Permalink
Detailed error message when module loader is not found
Browse files Browse the repository at this point in the history
  • Loading branch information
tkonolige committed Jul 27, 2020
1 parent 321cae2 commit 616fd3f
Show file tree
Hide file tree
Showing 2 changed files with 34 additions and 4 deletions.
19 changes: 17 additions & 2 deletions src/runtime/library_module.cc
Original file line number Diff line number Diff line change
Expand Up @@ -133,9 +133,24 @@ runtime::Module ProcessModuleBlob(const char* mblob, ObjectPtr<Library> lib) {
CHECK(stream->Read(&import_tree_row_ptr));
CHECK(stream->Read(&import_tree_child_indices));
} else {
std::string fkey = "runtime.module.loadbinary_" + tkey;
std::string loadkey = "runtime.module.loadbinary_";
std::string fkey = loadkey + tkey;
const PackedFunc* f = Registry::Get(fkey);
CHECK(f != nullptr) << "Loader of " << tkey << "(" << fkey << ") is not presented.";
if (f == nullptr) {
std::string loaders = "";
for (auto name : Registry::ListNames()) {
if (name.rfind(loadkey, 0) == 0) {
if (loaders.size() > 0) {
loaders += ", ";
}
loaders += name.substr(loadkey.size());
}
}
CHECK(f != nullptr)
<< "Binary was created using " << tkey
<< " but a loader of that name is not registered. Available loaders are " << loaders
<< ". Perhaps you need to recompile with this runtime enabled.";
}
Module m = (*f)(static_cast<void*>(stream));
modules.emplace_back(m);
}
Expand Down
19 changes: 17 additions & 2 deletions src/runtime/stackvm/stackvm_module.cc
Original file line number Diff line number Diff line change
Expand Up @@ -101,9 +101,24 @@ class StackVMModuleNode : public runtime::ModuleNode {
for (uint64_t i = 0; i < num_imports; ++i) {
std::string tkey;
CHECK(strm->Read(&tkey));
std::string fkey = "runtime.module.loadbinary_" + tkey;
std::string loadkey = "runtime.module.loadbinary_";
std::string fkey = loadkey + tkey;
const PackedFunc* f = Registry::Get(fkey);
CHECK(f != nullptr) << "Loader of " << tkey << "(" << fkey << ") is not presented.";
if (f == nullptr) {
std::string loaders = "";
for (auto name : Registry::ListNames()) {
if (name.rfind(loadkey, 0) == 0) {
if (loaders.size() > 0) {
loaders += ", ";
}
loaders += name.substr(loadkey.size());
}
}
CHECK(f != nullptr)
<< "Binary was created using " << tkey
<< " but a loader of that name is not registered. Available loaders are " << loaders
<< ". Perhaps you need to recompile with this runtime enabled.";
}
Module m = (*f)(static_cast<void*>(strm));
n->imports_.emplace_back(std::move(m));
}
Expand Down

0 comments on commit 616fd3f

Please sign in to comment.