premake-core icon indicating copy to clipboard operation
premake-core copied to clipboard

Further improved include error messages

Open richard-sim opened this issue 1 year ago • 3 comments

What does this PR do?

This is a continuation of my previous PR (CC @samsinsane - it's me again sorry!), improving the error message output for include() a bit, making it more precise and with less redundancy. I've also given the same love I gave to include() to includeexternal(), since it's essentially the same function.

How does this PR change Premake's behavior?

includeexternal() did not used to return the result of executing the included script, whereas include() did. I believe this was an oversight, as the documentation states that includeexternal() "works just like include()". I don't see this change causing harm since it was previously not returning any value, so I doubt there's any code relying on it returning nil. I have run the unit tests to be sure, and they're all green.

Example of an error from an include directly in the root premake5.lua

Error: ** Error: D:\dev\build-sys-eval\foobar\src\premake5.lua(36): include($/self-test/test_declare.lua) execution error: [string "self-test/test_declare.lua"]:6: attempt to index a nil value (local 'm')

Examples of errors from nested includes, with multiple-levels of include context

Example output of a missing include file:

Error: ** Error: D:\dev\build-sys-eval\foobar\src\premake5.lua(33): include(tools/premake/badcode.lua) execution error: ** Error: D:\dev\build-sys-eval\foobar\src\tools\premake\badcode.lua(1): include(no-file-here) not found or failed to load: ** Error: Cannot find neither no-file-here nor no-file-here.lua nor no-file-here/premake5.lua nor no-file-here/premake4.lua

Example output of a syntax error in an include file:

Error: ** Error: D:\dev\build-sys-eval\foobar\src\premake5.lua(21): include(foobar/L1a) not found or failed to load: ** Error: Error loading 'foobar/L1a: D:/dev/build-sys-eval/foobar/src/foobar/L1a/premake5.lua:8: syntax error near ']'

Example output of an incorrectly loaded internal script:

Error: ** Error: D:\dev\build-sys-eval\foobar\src\foobar\L1a\premake5.lua(30): include(tools/premake/badcode.lua) execution error: ** Error: D:\dev\build-sys-eval\foobar\src\tools\premake\badcode.lua(59): include($/self-test/test_declare.lua) execution error: [string "self-test/test_declare.lua"]:6: attempt to index a nil value (local 'm')

Anything else we should know?

n/a

Did you check all the boxes?

  • [x] Focus on a single fix or feature; remove any unrelated formatting or code changes
  • [x] Add unit tests showing fix or feature works; all tests pass
  • [x] Mention any related issues (put closes #XXXX in comment to auto-close issue when PR is merged)
  • [x] Follow our coding conventions
  • [x] Minimize the number of commits
  • [x] Align documentation to your changes

richard-sim avatar Sep 28 '24 05:09 richard-sim

Conflicts to resolve, and wonder if includeexternal should have same changes to support embed script. Sad that those 2 equivalent functions are separated in 2 files :/

Jarod42 avatar Sep 30 '24 15:09 Jarod42

Just poking on this to resolve the conflicts

nickclark2016 avatar Nov 20 '24 15:11 nickclark2016

Oops - I'll get on this in the next few days!

richard-sim avatar Jan 10 '25 10:01 richard-sim