Skip to content
Open
Show file tree
Hide file tree
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
2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@ The [ulx group permissions menu](https://hostr.co/spJgT4MnCrbg) or the correspon
I highly recommend tuning these permissions and being careful with the spew/errors. They might contain information that isn't for all eyes.

## Requirements
- Optional; to view errors: [gm_luaerror2](https://bitbucket.org/danielga/gm_luaerror2/downloads) (server version);
- Optional; to view errors: [gm_luaerror](https://bitbucket.org/danielga/gm_luaerror/downloads) (server version);
- Optional; to capture all the engine spew: [gm_enginespew](http://christopherthorne.googlecode.com/svn/trunk/gm_enginespew/Release/).

Make sure you rename the module(s) appropriately when necessary.
85 changes: 21 additions & 64 deletions lua/relc/singularity/sv_engine.lua
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ local type, tostring, pcall, hook = type, tostring, pcall, hook


local hasEngineSpew, engineSpew = pcall(require, "enginespew")
local hasLuaError, luaError = pcall(require, "luaerror2")
local hasLuaError, luaError = pcall(require, "luaerror")



Expand Down Expand Up @@ -47,77 +47,34 @@ if hasEngineSpew then
end

if hasLuaError then
local catching, queue = false, RelC.Queue(20)
if luaerror == nil or luaerror.VersionNum < 10200 then
-- Nothing to do here, bad/old module.

hook.Add("LuaError", "Relay Console", function(serverside, err, stack)
-- Making sure stuff is alright.
MsgC(Color(255, 0, 0), "Bad/outdated gm_luaerror module.")
return
end

if type(err) ~= "string" or (stack ~= nil and type(stack) ~= "table") then
MsgC(Color(255, 0, 0), "Messed up error: ")
MsgN("(", type(err), ") ", tostring(err), " - ", "(", type(stack), ") ", tostring(stack))
-- Enable all the detours to provide the same functionality as gm_luaerror2.

-- This kind of errors are bogus - not actual errors.
luaerror.EnableRuntimeDetour(true)
luaerror.EnableCompiletimeDetour(true)
luaerror.EnableClientDetour(true)

return
elseif stack == nil then
stack = {}--RelC.Utils.AcquireStack(2, true)
end

-- Fixing possible problems...

local a, b, source, line, errstr = find(err, "(.+):([%-%d]+): (.+)")
hook.Add("LuaError", "Relay Console", function(isruntime, errstr, file, line, err, stack)
-- Complete compiletime errors stack.

if a == 1 and b == #err and type(errstr) == "string" and #errstr > 0 then
err = errstr

if #stack == 0 then
stack[1] = {
source = source,
currentline = tonumber(line),
name = "unknown; inferred"
}

stack[2] = {
source = "MISSING STACK INFORMATION!",
currentline = -1,
name = "unknown"
}
end
if not isruntime then
table.insert(stack, 1, {
name = "unknown",
source = file,
currentline = line
})
end

-- Preventing recursive errors.

if catching then
queue:Queue({ err, stack })

MsgC(Color(255, 0, 0), "Captured error that would cause infinite recursion:\n")
PrintTable({ err, stack })
else
catching = true

hook_luaErrorSV(err, stack)

catching = false
end
hook_luaErrorSV(err, stack)
end)

hook.Add("Think", "Relay Console LuaError Decongestion", function()
while not queue:IsEmpty() do
catching = true

hook_luaErrorSV(unpack(queue:Dequeue()))

catching = false
end
end)



hook.Add("ClientLuaError", "Relay Console", function(ply, txt)
local err, stack = DecodeClientsideErrorString(txt)

-- Decoding is done here because a better engine interface could provide the necessary data directly.

hook_luaErrorCL(ply, err, stack)
hook.Add("ClientLuaError", "Relay Console", function(ply, errstr, file, line, err, stack)
hook_luaErrorCL(ply, err or errstr, stack)
end)
end
9 changes: 6 additions & 3 deletions lua/relc/singularity/utils/sh_strings.lua
Original file line number Diff line number Diff line change
Expand Up @@ -24,10 +24,13 @@ end
function RelC.Utils.DecodeClientsideErrorString(txt)
local stack, err = {}, ""

local path, line, errmsg, stacktrace = match(txt, "%[ERROR%] (.-):(.-):%s*(.-)\n*%s*(.+)$")
local path, line, errmsg, stacktrace = match(txt, "^([^:]+):([^:]+):%s+([^\n]+)(.+)$")

if not path or not line or not errmsg or not stacktrace then
error("Text given does not contain a valid/known error string! path: " .. tostring(path) .. "; line: " .. tostring(line) .. "; errmsg: " .. tostring(errmsg) .. "; stacktrace: " .. tostring(stacktrace) .. "; txt: " .. tostring(txt))
-- If we can't find a pattern, return the string we received.
-- This supports ErrorNoHalt and friends.

return txt, stack
end

--[[ uncomment this if you want to include the first error in the returned table
Expand All @@ -40,7 +43,7 @@ function RelC.Utils.DecodeClientsideErrorString(txt)

err = errmsg

for funcname, path, line in gmatch(stacktrace, "%s*%d+%. *(.-) *%- *(.-):(.-)\n") do
for funcname, path, line in gmatch(stacktrace, "%s+%d+%.%s+([^%s]+)%s+%-%s+([^:]+):([^\n]+)") do
stack[#stack+1] = {
source = path,
currentline = tonumber(line),
Expand Down