diff --git a/README.md b/README.md index 94f66de..e5ff5e1 100644 --- a/README.md +++ b/README.md @@ -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. diff --git a/lua/relc/singularity/sv_engine.lua b/lua/relc/singularity/sv_engine.lua index e20c0f3..c14b2b4 100644 --- a/lua/relc/singularity/sv_engine.lua +++ b/lua/relc/singularity/sv_engine.lua @@ -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") @@ -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 diff --git a/lua/relc/singularity/utils/sh_strings.lua b/lua/relc/singularity/utils/sh_strings.lua index 2ce1ee4..75fa50e 100644 --- a/lua/relc/singularity/utils/sh_strings.lua +++ b/lua/relc/singularity/utils/sh_strings.lua @@ -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 @@ -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),