diff --git a/src/vm/wren_vm.c b/src/vm/wren_vm.c index 2b2dc2ac..af6a235f 100644 --- a/src/vm/wren_vm.c +++ b/src/vm/wren_vm.c @@ -506,12 +506,17 @@ static Value importModule(WrenVM* vm, Value name) char* source = vm->config.loadModuleFn(vm, AS_CSTRING(name)); if (source == NULL) { - // Couldn't load the module. - vm->fiber->error = wrenStringFormat(vm, "Could not find module '@'.", name); + vm->fiber->error = wrenStringFormat(vm, "Could not load module '@'.", name); return NULL_VAL; } ObjFiber* moduleFiber = loadModule(vm, name, source); + if (moduleFiber == NULL) + { + vm->fiber->error = wrenStringFormat(vm, + "Could not compile module '@'.", name); + return NULL_VAL; + } // Return the fiber that executes the module. return OBJ_VAL(moduleFiber); diff --git a/test/language/module/compile_error/compile_error.wren b/test/language/module/compile_error/compile_error.wren new file mode 100644 index 00000000..86141630 --- /dev/null +++ b/test/language/module/compile_error/compile_error.wren @@ -0,0 +1,2 @@ +System.print("before") // expect: before +import "module" for Module // expect runtime error: Could not compile module 'module'. diff --git a/test/language/module/compile_error/module.wren b/test/language/module/compile_error/module.wren new file mode 100644 index 00000000..f65f6ca5 --- /dev/null +++ b/test/language/module/compile_error/module.wren @@ -0,0 +1,2 @@ +// nontest +undefined diff --git a/test/language/module/unknown_module.wren b/test/language/module/unknown_module.wren index 878708ec..6b096cb2 100644 --- a/test/language/module/unknown_module.wren +++ b/test/language/module/unknown_module.wren @@ -1 +1 @@ -import "does_not_exist" for DoesNotExist // expect runtime error: Could not find module 'does_not_exist'. +import "does_not_exist" for DoesNotExist // expect runtime error: Could not load module 'does_not_exist'. diff --git a/util/test.py b/util/test.py index 54e113ce..fdf0eac2 100755 --- a/util/test.py +++ b/util/test.py @@ -173,15 +173,20 @@ class Test: self.runtime_error_message) return - # Make sure we got the right error. - if error_lines[0] != self.runtime_error_message: + # Skip any compile errors. This can happen if there is a compile error in + # a module loaded by the module being tested. + line = 0 + while ERROR_PATTERN.search(error_lines[line]): + line += 1 + + if error_lines[line] != self.runtime_error_message: self.fail('Expected runtime error "{0}" and got:', self.runtime_error_message) - self.fail(error_lines[0]) + self.fail(error_lines[line]) # Make sure the stack trace has the right line. Skip over any lines that # come from builtin libraries. - stack_lines = error_lines[1:] + stack_lines = error_lines[line + 1:] for stack_line in stack_lines: match = STACK_TRACE_PATTERN.search(stack_line) if match: break