From 5ae02a65043d00dcae73e08c9bcc42bdef4745b7 Mon Sep 17 00:00:00 2001 From: Daniel Date: Tue, 14 Jul 2015 23:44:33 +0100 Subject: [PATCH 1/2] Updated gm_luaerror support code for the newest version. Updated readme. --- README.md | 2 +- lua/relc/singularity/sv_engine.lua | 82 +++++++----------------------- 2 files changed, 20 insertions(+), 64 deletions(-) diff --git a/README.md b/README.md index 39d447c..ce1f397 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](http://s.vercas.com/hdqvx) (cannot find original); +- Optional; to view errors: [gm_luaerror](https://bitbucket.org/danielga/gm_luaerror/downloads); - 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..a86b15d 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,33 @@ if hasEngineSpew then end if hasLuaError then - local catching, queue = false, RelC.Queue(20) + if luaerror == nil then + -- Nothing to do here, bad module. - hook.Add("LuaError", "Relay Console", function(serverside, err, stack) - -- Making sure stuff is alright. + 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_luaerror. - -- 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, file, line, err, stack) + -- Simulate Garry's Mod behavior if it's a compiletime error and stack is empty. - 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 and #stack == 0 then + stack[1] = { + source = file, + currentline = line, + name = "unknown" + } 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.Add("ClientLuaError", "Relay Console", function(ply, file, line, err, stack) hook_luaErrorCL(ply, err, stack) end) end From 345e137d6745b80298e2422f9926d80c7ae97c00 Mon Sep 17 00:00:00 2001 From: Daniel Date: Wed, 15 Jul 2015 22:20:23 +0100 Subject: [PATCH 2/2] Updated gm_luaerror support. Added check for gm_luaerror version. Runtime errors add a stack entry stating the error origin file. Added support for ErrorNoHalt and friends on ClientLuaError hook. Improved clientside error decoder (was being used before gm_luaerror update). --- lua/relc/singularity/Utils/sh_strings.lua | 9 +++++--- lua/relc/singularity/sv_engine.lua | 25 ++++++++++++----------- 2 files changed, 19 insertions(+), 15 deletions(-) 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), diff --git a/lua/relc/singularity/sv_engine.lua b/lua/relc/singularity/sv_engine.lua index a86b15d..c14b2b4 100644 --- a/lua/relc/singularity/sv_engine.lua +++ b/lua/relc/singularity/sv_engine.lua @@ -47,33 +47,34 @@ if hasEngineSpew then end if hasLuaError then - if luaerror == nil then - -- Nothing to do here, bad module. + if luaerror == nil or luaerror.VersionNum < 10200 then + -- Nothing to do here, bad/old module. + MsgC(Color(255, 0, 0), "Bad/outdated gm_luaerror module.") return end - -- Enable all the detours to provide the same functionality as gm_luaerror. + -- Enable all the detours to provide the same functionality as gm_luaerror2. luaerror.EnableRuntimeDetour(true) luaerror.EnableCompiletimeDetour(true) luaerror.EnableClientDetour(true) - hook.Add("LuaError", "Relay Console", function(isruntime, file, line, err, stack) - -- Simulate Garry's Mod behavior if it's a compiletime error and stack is empty. + hook.Add("LuaError", "Relay Console", function(isruntime, errstr, file, line, err, stack) + -- Complete compiletime errors stack. - if not isruntime and #stack == 0 then - stack[1] = { + if not isruntime then + table.insert(stack, 1, { + name = "unknown", source = file, - currentline = line, - name = "unknown" - } + currentline = line + }) end hook_luaErrorSV(err, stack) end) - hook.Add("ClientLuaError", "Relay Console", function(ply, file, line, err, stack) - 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