Skip to content
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
30 changes: 16 additions & 14 deletions lua/starfall/instance.lua
Original file line number Diff line number Diff line change
Expand Up @@ -594,10 +594,8 @@ function SF.Instance:runExternal(func, ...)
return ok, err
end

local function xpcall_callback(err)
if dgetmeta(err)~=SF.Errormeta then
return SF.MakeError(err, 1)
end
local function makeError(err)
if dgetmeta(err)~=SF.Errormeta then err = SF.MakeError(err, 1) end
return err
end

Expand All @@ -610,7 +608,7 @@ function SF.Instance:runWithOps(func, ...)

self.stackn = self.stackn + 1
self:pushCpuCheck(self.checkCpuHook)
local tbl = { xpcall(func, xpcall_callback, ...) }
local tbl = { xpcall(func, makeError, ...) }
self:popCpuCheck()
self.stackn = self.stackn - 1

Expand All @@ -623,7 +621,7 @@ function SF.Instance:runWithOps(func, ...)
end

function SF.Instance:runWithoutOps(func, ...)
return { xpcall(func, xpcall_callback, ...) }
return { xpcall(func, makeError, ...) }
end

function SF.Instance:initialize()
Expand All @@ -637,8 +635,9 @@ function SF.Instance:initialize()
if func then
local tbl = self:run(func)
if not tbl[1] then
self:Error(tbl[2])
return false, tbl[2]
local err = makeError(tbl[2])
self:Error(err)
return false, err
end
end

Expand All @@ -652,8 +651,9 @@ function SF.Instance:runScriptHook(hook, ...)
for name, func in hooks:pairs() do
tbl = self:run(func, ...)
if not tbl[1] then
tbl[2].message = "Hook '" .. hook .. "' errored with: " .. tostring(tbl[2].message)
self:Error(tbl[2])
local err = makeError(tbl[2])
err.message = "Hook '" .. hook .. "' errored with: " .. tostring(err.message)
self:Error(err)
return tbl
end
end
Expand All @@ -671,8 +671,9 @@ function SF.Instance:runScriptHookForResult(hook, ...)
break
end
else
tbl[2].message = "Hook '" .. hook .. "' errored with: " .. tostring(tbl[2].message)
self:Error(tbl[2])
local err = makeError(tbl[2])
err.message = "Hook '" .. hook .. "' errored with: " .. tostring(err.message)
self:Error(err)
return tbl
end
end
Expand All @@ -682,8 +683,9 @@ end
function SF.Instance:runFunction(func, ...)
local tbl = self:run(func, ...)
if not tbl[1] then
tbl[2].message = "Callback errored with: " .. tostring(tbl[2].message)
self:Error(tbl[2])
local err = makeError(tbl[2])
err.message = "Callback errored with: " .. tostring(err.message)
self:Error(err)
end

return tbl
Expand Down