summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorOpportunityLiu <[email protected]>2019-07-25 21:27:00 +0800
committerOpportunityLiu <[email protected]>2019-07-25 21:27:00 +0800
commit7d4023cf698bff82b2c0f2b4aad86286d4890b49 (patch)
treea51cbb284bac42523a2b9d35ad0f28a1942b89c4
parentb724d37e01b4a12d1b5eea3a9a866ba4b8c4e46d (diff)
add reference loop error
-rw-r--r--xmake/core/base/serialize.lua17
1 files changed, 15 insertions, 2 deletions
diff --git a/xmake/core/base/serialize.lua b/xmake/core/base/serialize.lua
index 4a9392ebe..e9b435387 100644
--- a/xmake/core/base/serialize.lua
+++ b/xmake/core/base/serialize.lua
@@ -214,7 +214,15 @@ function serialize.save(object, opt)
end
-- make string
- local result, errors = serialize._make(object, opt, 0)
+ local ok, result, errors = pcall(serialize._make, object, opt, 0)
+
+ if not ok then
+ if result:find("stack overflow", 1, true) then
+ errors = "cannot serialize: reference loop found"
+ else
+ errors = "cannot serialize: " .. result
+ end
+ end
-- ok?
if errors ~= nil then
@@ -226,11 +234,16 @@ function serialize.save(object, opt)
end
-- binary mode
- local dump, lerr = serialize._dump(loadstring("return " .. result), true)
+ local func, lerr = loadstring("return " .. result)
if lerr ~= nil then
return nil, lerr
end
+ local dump, derr = serialize._dump(func, true)
+ if derr ~= nil then
+ return nil, derr
+ end
+
-- return shorter representation
return (#dump < #result) and dump or result
end