summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorOpportunityLiu <[email protected]>2019-07-22 11:02:35 +0800
committerOpportunityLiu <[email protected]>2019-07-22 12:07:03 +0800
commit98c3052c933d988aa9e56aa433c433e7274164db (patch)
treede3ea686c7c04bff82d875acc24a905e313ded76
parent06b91f200e5c2f918624002a8989ddda61389930 (diff)
add level to error
-rw-r--r--.gitignore1
-rw-r--r--xmake/core/base/os.lua22
-rw-r--r--xmake/core/sandbox/modules/utils.lua8
3 files changed, 22 insertions, 9 deletions
diff --git a/.gitignore b/.gitignore
index 36a3f457c..81f2662bb 100644
--- a/.gitignore
+++ b/.gitignore
@@ -19,6 +19,7 @@ winenv/
*.exe
*.zip
*.run
+/xmake/*.md
# Makefile generation
/core/xmake.config.h
diff --git a/xmake/core/base/os.lua b/xmake/core/base/os.lua
index 2f17ebc27..b8d767efd 100644
--- a/xmake/core/base/os.lua
+++ b/xmake/core/base/os.lua
@@ -706,7 +706,10 @@ end
--
-- the parent function will capture it if we uses pcall or xpcall
--
-function os.raise(msg, ...)
+function os.raiselevel(level, msg, ...)
+
+ -- set level of this function
+ level = level + 1
-- flush log
log:flush()
@@ -716,19 +719,28 @@ function os.raise(msg, ...)
-- raise it
if type(msg) == "string" then
- error(string.tryformat(msg, ...))
+ error(string.tryformat(msg, ...), level)
elseif type(msg) == "table" then
local errobjstr, errors = string.serialize(msg, true)
if errobjstr then
- error("[@encode(error)]: " .. errobjstr)
+ error("[@encode(error)]: " .. errobjstr, level)
else
- error(errors)
+ error(errors, level)
end
else
- error()
+ error(tostring(msg), level)
end
end
+-- raise an exception and abort the current script
+--
+-- the parent function will capture it if we uses pcall or xpcall
+--
+function os.raise(msg, ...)
+ -- add return to make it a tail call
+ return os.raiselevel(1, msg, ...)
+end
+
-- is executable program file?
function os.isexec(filepath)
diff --git a/xmake/core/sandbox/modules/utils.lua b/xmake/core/sandbox/modules/utils.lua
index a81c84ded..f71d2a72b 100644
--- a/xmake/core/sandbox/modules/utils.lua
+++ b/xmake/core/sandbox/modules/utils.lua
@@ -20,6 +20,7 @@
-- load modules
local io = require("base/io")
+local os = require("base/os")
local utils = require("base/utils")
local colors = require("base/colors")
local option = require("base/option")
@@ -27,7 +28,6 @@ local log = require("base/log")
local try = require("sandbox/modules/try")
local catch = require("sandbox/modules/catch")
local vformat = require("sandbox/modules/vformat")
-local raise = require("sandbox/modules/raise")
-- define module
local sandbox_utils = sandbox_utils or {}
@@ -173,13 +173,13 @@ function sandbox_utils.assert(value, format, ...)
-- check
if not value then
if format ~= nil then
- raise(format, ...)
+ os.raiselevel(2, format, ...)
else
- raise("assertion failed!")
+ os.raiselevel(2, "assertion failed!")
end
end
- -- return it
+ -- return it
return value
end