Skip to content

Commit b7f4e1b

Browse files
authored
Merge pull request #2264 from richard-sim/show-error-context-for-broken-include
Show error messages from broken includes
2 parents 711f1ff + a514ebe commit b7f4e1b

File tree

2 files changed

+22
-8
lines changed

2 files changed

+22
-8
lines changed

src/base/_foundation.lua

+10-4
Original file line numberDiff line numberDiff line change
@@ -242,11 +242,17 @@
242242
local p5 = path.join(fname, "premake5.lua")
243243
local p4 = path.join(fname, "premake4.lua")
244244

245+
local compiled_chunk
245246
local res = os.locate(fname, with_ext, p5, p4)
246-
res = res or fname
247-
local compiled_chunk = loadfile(res)
248-
if compiled_chunk == nil then
249-
premake.error("Cannot find either " .. table.implode({fname, with_ext, p5, p4}, "", "", " or "))
247+
if res == nil then
248+
local caller = filelineinfo(3)
249+
premake.error(caller .. ": Cannot find neither " .. table.implode({fname, with_ext, p5, p4}, "", "", " nor "))
250+
else
251+
compiled_chunk, err = loadfile(res)
252+
if err ~= nil then
253+
local caller = filelineinfo(3)
254+
premake.error(caller .. ": Error loading '" .. fname .. ": " .. err)
255+
end
250256
end
251257
return res, compiled_chunk
252258
end

src/base/globals.lua

+12-4
Original file line numberDiff line numberDiff line change
@@ -48,10 +48,18 @@
4848
io._includedFiles = {}
4949

5050
function include(fname)
51-
fname, compiled_chunk = premake.findProjectScript(fname)
52-
if not io._includedFiles[fname] then
53-
io._includedFiles[fname] = true
54-
return compiled_chunk()
51+
local actualFname, compiled_chunk = premake.findProjectScript(fname)
52+
if not io._includedFiles[actualFname] then
53+
io._includedFiles[actualFname] = true
54+
local success, res = pcall(compiled_chunk)
55+
if success then
56+
-- res is the return value of the script
57+
return res
58+
else
59+
-- res is the error message
60+
local caller = filelineinfo(2)
61+
premake.error(caller .. ": Error executing '" .. fname .. ": " .. res)
62+
end
5563
end
5664
end
5765

0 commit comments

Comments
 (0)