add: error testing + report

This commit is contained in:
Linventif 2024-07-01 05:05:49 +00:00
parent 0f7dbb297f
commit ee1e2caf30
3 changed files with 57 additions and 30 deletions

View File

@ -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

View File

@ -2,22 +2,29 @@
// 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)
function gmInte.sendLuaErrorReport(err, realm, stack, name, id)
cacheErrors[err] = {
["time"] = CurTime(),
["count"] = cacheErrors[err] && cacheErrors[err].count + 1 || 1,
}
if (!gmInte.config.id || !gmInte.config.token) then return end
if (CLIENT && !IsValid(LocalPlayer())) then return end
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
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
local endpoint = SERVER && "/servers/:serverID/errors" || "/clients/:steamID64/errors"
local endpoint = SERVER && "/servers/:serverID/errors" || "/clients/:steamID64/servers/:serverID/errors"
gmInte.http.post(endpoint,
{
["error"] = err,
@ -25,10 +32,12 @@ function gmInte.sendLuaErrorReport(err, realm, stack, name, id, uptime)
["stack"] = stack,
["name"] = name,
["id"] = id,
["uptime"] = uptime || math.Round(RealTime()),
["identifier"] = SERVER && gmInte.config.id || LocalPlayer():SteamID64()
["count"] = count,
["uptime"] = math.Round(RealTime()),
["identifier"] = SERVER && gmInte.config.id || CLIENT && LocalPlayer():SteamID64()
}
)
end)
end
//

View File

@ -38,3 +38,26 @@ function gmInte.isPrivateIP(ip)
if (parts[1] == "127") then return true end
return false
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)