mirror of
https://github.com/gmod-integration/lua.git
synced 2025-03-15 22:07:34 +00:00
add: error testing + report
This commit is contained in:
parent
0f7dbb297f
commit
ee1e2caf30
|
@ -18,11 +18,6 @@ local colorTbl = {
|
|||
["font-secondary"] = Color(179, 179, 179)
|
||||
}
|
||||
|
||||
// con cmd how create a error
|
||||
concommand.Add("gmi_error", function()
|
||||
error("This is a test error")
|
||||
end)
|
||||
|
||||
function gmInte.getColor(name)
|
||||
return colorTbl[name]
|
||||
end
|
||||
|
|
|
@ -2,33 +2,42 @@
|
|||
// Methods
|
||||
//
|
||||
|
||||
function gmInte.sendLuaErrorReport(err, realm, stack, name, id, uptime)
|
||||
if (string.find(err, "Gmod Integration")) then return end
|
||||
local cacheErrors = {}
|
||||
|
||||
if (SERVER && math.Round(RealTime()) == 0) then
|
||||
return timer.Simple(1, function()
|
||||
gmInte.sendLuaErrorReport(err, realm, stack, name, id, math.Round(RealTime()))
|
||||
end)
|
||||
end
|
||||
function gmInte.sendLuaErrorReport(err, realm, stack, name, id)
|
||||
cacheErrors[err] = {
|
||||
["time"] = CurTime(),
|
||||
["count"] = cacheErrors[err] && cacheErrors[err].count + 1 || 1,
|
||||
}
|
||||
|
||||
if (CLIENT && (!IsValid(LocalPlayer()) || !gmInte.config.token)) then
|
||||
return timer.Simple(1, function()
|
||||
gmInte.sendLuaErrorReport(err, realm, stack, name, id, math.Round(RealTime()))
|
||||
end)
|
||||
end
|
||||
if (!gmInte.config.id || !gmInte.config.token) then return end
|
||||
if (CLIENT && !IsValid(LocalPlayer())) then return end
|
||||
|
||||
local endpoint = SERVER && "/servers/:serverID/errors" || "/clients/:steamID64/errors"
|
||||
gmInte.http.post(endpoint,
|
||||
{
|
||||
["error"] = err,
|
||||
["realm"] = realm,
|
||||
["stack"] = stack,
|
||||
["name"] = name,
|
||||
["id"] = id,
|
||||
["uptime"] = uptime || math.Round(RealTime()),
|
||||
["identifier"] = SERVER && gmInte.config.id || LocalPlayer():SteamID64()
|
||||
}
|
||||
)
|
||||
local count = cacheErrors[err].count
|
||||
timer.Simple(0.5, function()
|
||||
if (cacheErrors[err].count != count) then
|
||||
if (cacheErrors[err].count == 100) then
|
||||
else
|
||||
return
|
||||
end
|
||||
else
|
||||
cacheErrors[err] = nil
|
||||
end
|
||||
|
||||
local endpoint = SERVER && "/servers/:serverID/errors" || "/clients/:steamID64/servers/:serverID/errors"
|
||||
gmInte.http.post(endpoint,
|
||||
{
|
||||
["error"] = err,
|
||||
["realm"] = realm,
|
||||
["stack"] = stack,
|
||||
["name"] = name,
|
||||
["id"] = id,
|
||||
["count"] = count,
|
||||
["uptime"] = math.Round(RealTime()),
|
||||
["identifier"] = SERVER && gmInte.config.id || CLIENT && LocalPlayer():SteamID64()
|
||||
}
|
||||
)
|
||||
end)
|
||||
end
|
||||
|
||||
//
|
||||
|
|
|
@ -37,4 +37,27 @@ function gmInte.isPrivateIP(ip)
|
|||
if (parts[1] == "172" && tonumber(parts[2]) >= 16 && tonumber(parts[2]) <= 31) then return true end
|
||||
if (parts[1] == "127") then return true end
|
||||
return false
|
||||
end
|
||||
end
|
||||
|
||||
concommand.Add("gmi_test_error", function( ply, cmd, args )
|
||||
print(ply, cmd)
|
||||
PrintTable(args)
|
||||
if (#args == 0) then
|
||||
error("This is a test error")
|
||||
else
|
||||
if (args[1] == "loop") then
|
||||
hook.Add("Think", "gmInte:TestError:Loop", function()
|
||||
error("This is a test error")
|
||||
end)
|
||||
timer.Simple(5, function()
|
||||
hook.Remove("Think", "gmInte:TestError:Loop")
|
||||
end)
|
||||
elseif (args[1] == "crash") then
|
||||
while (true) do
|
||||
error("This is a crash error")
|
||||
end
|
||||
else
|
||||
error("This is a test error")
|
||||
end
|
||||
end
|
||||
end)
|
Loading…
Reference in New Issue
Block a user