Skip to content

Commit

Permalink
Merge pull request #2264 from richard-sim/show-error-context-for-brok…
Browse files Browse the repository at this point in the history
…en-include

Show error messages from broken includes
  • Loading branch information
samsinsane authored Sep 28, 2024
2 parents 711f1ff + a514ebe commit b7f4e1b
Show file tree
Hide file tree
Showing 2 changed files with 22 additions and 8 deletions.
14 changes: 10 additions & 4 deletions src/base/_foundation.lua
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
16 changes: 12 additions & 4 deletions src/base/globals.lua
Original file line number Diff line number Diff line change
Expand Up @@ -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

Expand Down

0 comments on commit b7f4e1b

Please sign in to comment.