diff options
| author | ruki <[email protected]> | 2019-08-23 00:55:19 +0800 |
|---|---|---|
| committer | ruki <[email protected]> | 2019-08-22 23:31:55 +0800 |
| commit | 1a736b3161b5959115caa43cdb6c8887e2aa99d5 (patch) | |
| tree | ef5c9cfbb72fb121d0dd45f393fc5a7776e929bc /xmake/core/base/utils.lua | |
| parent | 9504fe2932ff188662d3b4e05fb9de8782790bf3 (diff) | |
improve trycall
Diffstat (limited to 'xmake/core/base/utils.lua')
| -rw-r--r-- | xmake/core/base/utils.lua | 21 |
1 files changed, 18 insertions, 3 deletions
diff --git a/xmake/core/base/utils.lua b/xmake/core/base/utils.lua index 5b0c68a5e..584af7eb7 100644 --- a/xmake/core/base/utils.lua +++ b/xmake/core/base/utils.lua @@ -234,19 +234,34 @@ function utils.trycall(script, traceback, ...) if errors then local _, pos = errors:find("[@encode(error)]: ", 1, true) if pos then + -- strip traceback (maybe from coroutine.resume) local errs = errors:sub(pos + 1) + local stack = nil + local stackpos = errs:find("}\nstack traceback:", 1, true) + if stackpos and stackpos > 1 then + stack = errs:sub(stackpos + 2) + errs = errs:sub(1, stackpos) + end errors, errs = errs:deserialize() if not errors then errors = errs end if type(errors) == "table" then + if stack then + errors._stack = stack + end setmetatable(errors, { __tostring = function (self) - if self.errors then - return self.errors + local result = self.errors + if not result then + result = string.serialize(self, {strip = true, indent = false}) + end + result = result or "" + if self._stack then + result = result .. "\n" .. self._stack end - return string.serialize(self) + return result end, __concat = function (self, other) return tostring(self) .. tostring(other) |
