diff options
| author | ruki <[email protected]> | 2026-07-12 20:33:23 +0800 |
|---|---|---|
| committer | ruki <[email protected]> | 2026-07-12 20:35:03 +0800 |
| commit | fa89f0a96449a880b4d7a01bad80f9675e2eae2d (patch) | |
| tree | 90eb39b294579dcc3af9bb78ec416fd8ae7f49db /xmake/core/base | |
| parent | ee1256b0921f0e6318b092e6635b8674671297b0 (diff) | |
improve error tipserrs
Diffstat (limited to 'xmake/core/base')
| -rw-r--r-- | xmake/core/base/interpreter.lua | 20 |
1 files changed, 20 insertions, 0 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 |
