diff options
Diffstat (limited to 'xmake')
| -rw-r--r-- | xmake/core/base/interpreter.lua | 20 | ||||
| -rw-r--r-- | xmake/core/main.lua | 7 | ||||
| -rw-r--r-- | xmake/core/project/project.lua | 12 |
3 files changed, 38 insertions, 1 deletions
diff --git a/xmake/core/base/interpreter.lua b/xmake/core/base/interpreter.lua index bcf446309..83bbdf593 100644 --- a/xmake/core/base/interpreter.lua +++ b/xmake/core/base/interpreter.lua @@ -32,12 +32,29 @@ local scopeinfo = require("base/scopeinfo") local deprecated = require("base/deprecated") local sandbox = require("sandbox/sandbox") +-- the rules to reword the raw lua error messages into friendly ones, {pattern, replacement} +-- e.g. "attempt to call a nil value (global 'test')" -> "unknown interface: test()" +local _reword_rules = {{ + "attempt to call a nil value %(global '([%w_]+)'%)", + "unknown interface: %1(), please check the api name or its scope"} +} + -- raise without interpreter stack -- @see https://github.com/xmake-io/xmake/issues/3553 function interpreter._raise(errors) os.raise("[nobacktrace]: " .. (errors or "")) end +-- reword the raw error message to make it more friendly +function interpreter._reword_errors(errors) + if type(errors) == "string" then + for _, rule in ipairs(_reword_rules) do + errors = errors:gsub(rule[1], rule[2], 1) + end + end + return errors +end + -- traceback function interpreter._traceback(errors) @@ -49,6 +66,9 @@ function interpreter._traceback(errors) end end + -- reword the raw error message to make it more friendly + errors = interpreter._reword_errors(errors) + -- init results local results = "" if errors then diff --git a/xmake/core/main.lua b/xmake/core/main.lua index f3ad904f5..0c38840de 100644 --- a/xmake/core/main.lua +++ b/xmake/core/main.lua @@ -304,6 +304,13 @@ function main.entry() return main._exit(ok, errors) end + -- the project file failed to load when building the option menu? report it and exit now, + -- so that we do not continue into config/build and print the same error again later + local menu_load_error = project.menu_load_error() + if menu_load_error then + return main._exit(false, menu_load_error) + end + if xmake.in_main_thread() then -- check run command as root diff --git a/xmake/core/project/project.lua b/xmake/core/project/project.lua index ff770ced0..d1030f130 100644 --- a/xmake/core/project/project.lua +++ b/xmake/core/project/project.lua @@ -1324,6 +1324,11 @@ function project.mtimes() return mtimes end +-- get the error of loading the project file when building the option menu +function project.menu_load_error() + return project._memcache():get("menu_load_error") +end + -- get the project menu function project.menu() @@ -1341,7 +1346,12 @@ function project.menu() -- failed? if not options then - if errors then utils.error(errors) end + -- record the error and let main() report it once and exit, instead of continuing into + -- config/build and reporting it again. we cannot abort here directly, because we are inside + -- the sandboxed menu loader, which would wrap the clean error with extra prefixes. + if errors then + project._memcache():set("menu_load_error", errors) + end return {} end |
