From 5ec37965a2d23dd1d25b5a876300850778b99206 Mon Sep 17 00:00:00 2001 From: Tim Wharton Date: Sat, 1 Aug 2015 03:48:22 +0100 Subject: [PATCH] Improve module loadfile() error messages Have the module package loader return the loadfile() error for file system modules, and report the error from the calling script, rather than globals.lua. This give marginally better errors when require()'ing modules with syntax errors. The error will appear in the package loader list with the correct call site. Error: /Users/blah/premake5.lua:7: module 'wee' not found: no field package.preload['wee'] load error /Users/blah/modules/wee/wee.lua:3: '=' expected near '' .... --- src/_premake_main.lua | 3 +++ src/base/globals.lua | 5 ++++- 2 files changed, 7 insertions(+), 1 deletion(-) diff --git a/src/_premake_main.lua b/src/_premake_main.lua index 93589f22..355aebd2 100644 --- a/src/_premake_main.lua +++ b/src/_premake_main.lua @@ -68,6 +68,9 @@ if chunk then return chunk end + if err then + return "\n\tload error " .. err + end end end diff --git a/src/base/globals.lua b/src/base/globals.lua index 89911b57..cec61615 100644 --- a/src/base/globals.lua +++ b/src/base/globals.lua @@ -74,7 +74,10 @@ --- premake.override(_G, "require", function(base, modname, versions) - local mod = base(modname) + local result, mod = pcall(base,modname) + if not result then + error( mod, 3 ) + end if mod and versions and not premake.checkVersion(mod._VERSION, versions) then error(string.format("module %s %s does not meet version criteria %s", modname, mod._VERSION or "(none)", versions), 3)