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)
|
["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)
|
function gmInte.getColor(name)
|
||||||
return colorTbl[name]
|
return colorTbl[name]
|
||||||
end
|
end
|
||||||
|
|
|
@ -2,33 +2,42 @@
|
||||||
// Methods
|
// Methods
|
||||||
//
|
//
|
||||||
|
|
||||||
function gmInte.sendLuaErrorReport(err, realm, stack, name, id, uptime)
|
local cacheErrors = {}
|
||||||
if (string.find(err, "Gmod Integration")) then return end
|
|
||||||
|
|
||||||
if (SERVER && math.Round(RealTime()) == 0) then
|
function gmInte.sendLuaErrorReport(err, realm, stack, name, id)
|
||||||
return timer.Simple(1, function()
|
cacheErrors[err] = {
|
||||||
gmInte.sendLuaErrorReport(err, realm, stack, name, id, math.Round(RealTime()))
|
["time"] = CurTime(),
|
||||||
end)
|
["count"] = cacheErrors[err] && cacheErrors[err].count + 1 || 1,
|
||||||
end
|
}
|
||||||
|
|
||||||
if (CLIENT && (!IsValid(LocalPlayer()) || !gmInte.config.token)) then
|
if (!gmInte.config.id || !gmInte.config.token) then return end
|
||||||
return timer.Simple(1, function()
|
if (CLIENT && !IsValid(LocalPlayer())) then return end
|
||||||
gmInte.sendLuaErrorReport(err, realm, stack, name, id, math.Round(RealTime()))
|
|
||||||
end)
|
|
||||||
end
|
|
||||||
|
|
||||||
local endpoint = SERVER && "/servers/:serverID/errors" || "/clients/:steamID64/errors"
|
local count = cacheErrors[err].count
|
||||||
gmInte.http.post(endpoint,
|
timer.Simple(0.5, function()
|
||||||
{
|
if (cacheErrors[err].count != count) then
|
||||||
["error"] = err,
|
if (cacheErrors[err].count == 100) then
|
||||||
["realm"] = realm,
|
else
|
||||||
["stack"] = stack,
|
return
|
||||||
["name"] = name,
|
end
|
||||||
["id"] = id,
|
else
|
||||||
["uptime"] = uptime || math.Round(RealTime()),
|
cacheErrors[err] = nil
|
||||||
["identifier"] = SERVER && gmInte.config.id || LocalPlayer():SteamID64()
|
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
|
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] == "172" && tonumber(parts[2]) >= 16 && tonumber(parts[2]) <= 31) then return true end
|
||||||
if (parts[1] == "127") then return true end
|
if (parts[1] == "127") then return true end
|
||||||
return false
|
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