summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-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