diff options
| author | OpportunityLiu <[email protected]> | 2019-07-26 11:16:20 +0800 |
|---|---|---|
| committer | OpportunityLiu <[email protected]> | 2019-07-28 14:45:00 +0800 |
| commit | 39bd37f2a46ed9b5e6d02bcf68ecd5597ee85dfa (patch) | |
| tree | 334a604e4c6c591c4e14e588a6e3d55f4a87d445 /xmake/core/base/serialize.lua | |
| parent | 71d253bc95fe107ee401f37a8d6405fac96651fa (diff) | |
improve error message
Diffstat (limited to 'xmake/core/base/serialize.lua')
| -rw-r--r-- | xmake/core/base/serialize.lua | 32 |
1 files changed, 17 insertions, 15 deletions
diff --git a/xmake/core/base/serialize.lua b/xmake/core/base/serialize.lua index 8da0546c8..8bfc265c6 100644 --- a/xmake/core/base/serialize.lua +++ b/xmake/core/base/serialize.lua @@ -257,31 +257,33 @@ function serialize._load(str) str = "return " .. str end - local script, errors = loadstring(str) + -- load string + local script, errors = loadstring(str, "=(deserializing data)") if script then - -- load object local ok, object = pcall(script) if ok then result = object - elseif object then - -- error - errors = object else - local data - if binary then - data = "<binary data>" - elseif #str > 20 then - data = str:sub(8, 17) .. "..." - else - data = str:sub(8) - end -- error - errors = string.format("cannot deserialize string: %s", data) + errors = tostring(object) end end - return result, errors + if errors then + local data + if binary then + data = "<binary data>" + elseif #str > 30 then + data = string.format("%q... ", str:sub(8, 27)) + else + data = string.format("%q", str:sub(8)) + end + -- error + return nil, string.format("cannot deserialize %s: %s", data, errors) + end + + return result end -- deserialize string to object |
