Skip to content

Commit f3113e2

Browse files
kulcsaradamksh8281
authored andcommitted
Improve insufficient import error message
Error message is more verbose with module name, field name and type of import. Signed-off-by: Ádám László Kulcsár <[email protected]>
1 parent dd3021b commit f3113e2

File tree

2 files changed

+29
-1
lines changed

2 files changed

+29
-1
lines changed

src/runtime/Module.cpp

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -153,7 +153,12 @@ Instance* Module::instantiate(ExecutionState& state, const ExternVector& imports
153153
}
154154

155155
if (imports.size() < m_imports.size()) {
156-
Trap::throwException(state, "Insufficient import");
156+
std::string message = "Insufficient import(s):\n";
157+
158+
for (uint32_t i = imports.size(); i < m_imports.size(); i++) {
159+
message.append(" " + m_imports[i]->moduleName() + " : " + m_imports[i]->fieldName() + " -- Type:" + m_imports[i]->typeToString() + "\n");
160+
}
161+
Trap::throwException(state, message);
157162
}
158163

159164
for (size_t i = 0; i < m_imports.size(); i++) {

src/runtime/Module.h

Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -131,6 +131,29 @@ class ImportType {
131131
return static_cast<const MemoryType*>(m_type);
132132
}
133133

134+
std::string typeToString()
135+
{
136+
switch (m_importType) {
137+
case Type::Function: {
138+
return std::string("Function");
139+
}
140+
case Type::Global: {
141+
return std::string("Global");
142+
}
143+
case Type::Memory: {
144+
return std::string("Memory");
145+
}
146+
case Type::Table: {
147+
return std::string("Table");
148+
}
149+
case Type::Tag: {
150+
return std::string("Tag");
151+
}
152+
}
153+
154+
RELEASE_ASSERT_NOT_REACHED();
155+
}
156+
134157
private:
135158
Type m_importType;
136159
std::string m_moduleName;

0 commit comments

Comments
 (0)