Skip to content

Commit 5238489

Browse files
committed
Further improvements to error message display for includes
Integrated PR feedback: - It can be assumed that err is not nil if compiled_chunk is nil (confirmed with the lua docs) - Check if the file was located before trying to load it, so we can display a descriptive error message with the alternate names that were searched - Improved the error messages by addubg the file/line information where the include originated, similar to the output of a compiler. The `res` is not output to the error message as in every case it was already part of the error message that was returned and that resulted in very long, repetitive errors
1 parent 6703872 commit 5238489

File tree

1 file changed

+9
-7
lines changed

1 file changed

+9
-7
lines changed

src/base/_foundation.lua

+9-7
Original file line numberDiff line numberDiff line change
@@ -242,14 +242,16 @@
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, err = loadfile(res)
248-
if compiled_chunk == nil then
249-
if err then
250-
premake.error("Cannot load " .. fname .. ": " .. err)
251-
else
252-
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)
253255
end
254256
end
255257
return res, compiled_chunk

0 commit comments

Comments
 (0)