gm_luaerror2 - "ain't nobody got time fo dat error" edition

gm_luaerror is back!
Forget everything you knew about the old gm_luaerror. You now receive a full stack (if there is any) about the error as a table and whether it’s a runtime error or not (a compilation one). A great addition is the possibility to get the clients Lua errors on the server (as a plain string since that’s how Garry’s system works).

Enough chit chat. Let’s get dirty.

Example to receive normal Lua errors (whether they are compilation or runtime errors) and clients Lua errors (server only).


require("luaerror")
hook.Add("LuaError", "Error receiver", function(is_runtime_error, full_error, source_file, source_line, error_string, stack_table) print(is_runtime_error, full_error, source_file, source_line, error_string) if stack_table ~= nil then PrintTable(stack_table) end return true end)
hook.Add("ClientLuaError", "Clients errors receiver", function(player, full_error, source_file, source_line, error_string, stack_table) print(player, full_error, source_file, source_line, error_string) if stack_table ~= nil then PrintTable(stack_table) end return true end)

Notice how I check for the validity of stack. That’s because if there’s no stack (usually on compilation errors) you get a nil, otherwise a table indexed by numbers (level of debug) of tables with all these elements.

By returning true in any of those hooks, you will stop the normal flow of the games functions. Basically, no errors are printed (unless you print them yourself) and sent to Facepunch.

“But where’s the downloads?”

I was going to get to that but since you’re in a hurry/have no patience, here you go.

Source

Windows Client
Windows Server
These also need VC++ 2010 redistributables from here https://www.microsoft.com/en-us/download/details.aspx?id=26999

Linux Client
Linux Server

No Mac binaries. Sorry. I haven’t tested it as well in Mac since I don’t have a way of doing it. And don’t say “get a Mac VM” because no. I already tried it and it was slow as shit and could do nothing. I’m not even going to do a partition just for it. Got Linux and that’s enough.
If someone is kind enough to do it/test it for me, I’d appreciate it.

I’m really confused, but what does this do? Isn’t this already included in gmod?

This allows you to get the errors/stack on Lua and/or stop the printing and sending of them to Facepunch. GMod doesn’t have this by default (even though it was asked already before for such a feature).

I didn’t say this before, but this is very useful for remote servers (rented boxes and stuff) where you don’t have direct access to the console. You could use this to send the errors to a database, website, your home, anything. It was actually because of this that I started working on the module.

time to convert epoe to use this (or fallback to enginespew or nothingness) :v: thanks
Also thanks Garry for not even changing the spew type of lua error messages. This is where we are now.

Could I ask if anyone could do a compile of the Windows Server, of the most recent source?

You just made my life 10X easier. I HATE flushing the log, downloading it from my ftp, opening the log, searching for the error, adjusting, rinsing and repeating.

This will save A LOT of time! <3

I had totally forgotten about this. Windows builds are up. I might upload Linux ones sometime later.

This is quite useful.

e:
I have one gripe, though, why does the LuaError hook have a ‘serverside’ parameter? We already have CLIENT and SERVER for use in shared hooks, so including it as a param as well is redundant

(I could be missing something, I’m assuming it’s always true if called serverside and always false if clientside – the client module download is broken and I cannot into Visual Studio)

Are you sure the download link doesn’t work? I just tried it and it worked fine. The serverside parameter was just to prevent global table lookups when using SERVER and CLIENT since this hook can be called a big number of times per second (depending on the severity of the error). It can look pretty redundant currently but I don’t see any major reasons to remove it now.

Added new version of the Windows module.
Added Linux modules.

The link does work now.

I see your point, but shouldn’t it be consistent with the existing base and sandbox hooks? If you’re using a shared hook that’s called very often, Tick or Think or CalcMainActivity or whatever else, either you’re going to localize the globals yourself anyway – CLIENT, SERVER, string, table, your gamemode namespace, whatever else you use a lot – or you define the serverside and clientside functions separately.

That aside, I like it – it’s just the inconsistency that bugs me a little.

-snip- nevermind

Wooooo boyos! Improved error procedure overall. Less empty stacks, more fun. Actually, scratch that. No empty stacks at ALL! Made some changes to the hook parameters so be sure to check it out!

The no empty stacks is a bit of a hack though. When syntax errors are found on loading files or using lua_run* commands, there isn’t any stack, since no code has been ran at all. So I wonder if this is bad juju.

Linux?

Gonna do some more changes (sorry about this, it’s needed) and then do compilations for both systems. About the fake stack, I’m gonna remove it. It’s a hell of a hack and some people think it’s better to check for nils than an empty table. I’m gonna add a bool though that says whether it’s a compilation error or a runtime one.

New windows binaries up. Changes are documented on first post. Mostly they’re hook parameters. Also, you should still check if stack is nil and if that happens it’s most likely a compilation error (syntax error). Also fixed a crash caused by this module.

First of all, sorry to revive a dead thread, but I do need some help.

I installed this file directly into garrysmod/lua/bin.

Upon creating a file and copy pasting the code in the OP into it, saving the file, and restarting the server, I get an error saying that it could not find the module. AM I installing the .dll into the wrong place, or am I doing something else wrong?

If I remember correctly, you need VC++ 2013 redistributables.
It’s in the first post, below the Windows download links.

I do have those installed on my server. Is there anything else I could be doing wrong? Is there another .dll needed to make this work?

You need the VC++ 2013 32 bits (x86) redistributables.
You need the gmsv_ module.
The files needs to be inside garrysmod/lua/bin (which you already did).
Besides these, I have no idea what could be wrong. Too bad these kinds of errors are completely useless since they don’t say anything.

I did get it working. I had to download/install the version on github, not the version youv’e got linked in the forum post. If they’re the same, then I must’ve been doing somehting else wrong. In anycase, I’ve gotten the server side aspect working. As for the clientside, I’m getting this error:



[ERROR] Failed to load LuaError. 'Unable to sigscan function lj_err_lex (lua_shared.dll).' Contact me in Facepunch (danielga) or Steam (tuestu1) with this error.
  1. unknown - [C]:-1
   2. require - [C]:-1
    3. unknown - lua/autorun/test2.lua:4


whenever I try to include the clientside .dll

Module updated. I tested both server and client on Windows so it should work fine. I removed the dangerous detours I used on LuaJIT on moved them to better places. I basically recreate Garry’s method of stack reconstruction with my detours. It also has less ways of crashing because of these changes. I hope. Windows builds only for now. I need to test the Linux server build after building both.