diff --git a/src/base/_foundation.lua b/src/base/_foundation.lua index 8bb3d9b9f2..130be76bae 100644 --- a/src/base/_foundation.lua +++ b/src/base/_foundation.lua @@ -242,11 +242,17 @@ local p5 = path.join(fname, "premake5.lua") local p4 = path.join(fname, "premake4.lua") + local compiled_chunk local res = os.locate(fname, with_ext, p5, p4) - res = res or fname - local compiled_chunk = loadfile(res) - if compiled_chunk == nil then - premake.error("Cannot find either " .. table.implode({fname, with_ext, p5, p4}, "", "", " or ")) + if res == nil then + local caller = filelineinfo(3) + premake.error(caller .. ": Cannot find neither " .. table.implode({fname, with_ext, p5, p4}, "", "", " nor ")) + else + compiled_chunk, err = loadfile(res) + if err ~= nil then + local caller = filelineinfo(3) + premake.error(caller .. ": Error loading '" .. fname .. ": " .. err) + end end return res, compiled_chunk end diff --git a/src/base/globals.lua b/src/base/globals.lua index ee9385182e..d46ca00b68 100644 --- a/src/base/globals.lua +++ b/src/base/globals.lua @@ -48,10 +48,18 @@ io._includedFiles = {} function include(fname) - fname, compiled_chunk = premake.findProjectScript(fname) - if not io._includedFiles[fname] then - io._includedFiles[fname] = true - return compiled_chunk() + local actualFname, compiled_chunk = premake.findProjectScript(fname) + if not io._includedFiles[actualFname] then + io._includedFiles[actualFname] = true + local success, res = pcall(compiled_chunk) + if success then + -- res is the return value of the script + return res + else + -- res is the error message + local caller = filelineinfo(2) + premake.error(caller .. ": Error executing '" .. fname .. ": " .. res) + end end end