danielga / gm_luaerror

A module for Garry's Mod that adds hooks for obtaining errors that happen on the client and server (if activated on server, it also pushes errors from clients).
https://github.com/danielga/gm_luaerror
Other
54 stars 8 forks source link

Direct access to the error's stack? #9

Closed Lexicality closed 6 years ago

Lexicality commented 6 years ago

Hi, me again. Would it be possible to execute the hook or a callback at the peak of the error stack, like xpcall does?

] lua_run function a() error'a' end function b() a() end function c() b() end function d() c() end xpcall(d, function() print(debug.traceback()) end)
> function a() error'a' end function b() a() end function c() b() end function d() c() end xpcall(d, function() print(debug.traceback()) end)...
stack traceback:
    lua_run:1: in function <lua_run:1>
    [C]: in function 'error'
    lua_run:1: in function 'a'
    lua_run:1: in function 'b'
    lua_run:1: in function 'c'
    lua_run:1: in function <lua_run:1>
    [C]: in function 'xpcall'
    lua_run:1: in main chunk

I'm writing a sentry integration and would like to walk the stack myself to grab upvalues and the like.

danielga commented 6 years ago

@Lexicality would adding these upvalues/locals to the error stack provided by the LuaError hook suffice? I'd feel much more comfortable with this option and since I'm already retrieving the stack, might as well just add the rest of the data there. Less confusion of the users of the library by not having different options that seem to do the same, too.

Lexicality commented 6 years ago

Probably? My current plan is to try and catch a lot of errors via xpcall so I can pretag them with hook names/players etc, then fall back to the LuaError hook for things I can't intercept - so this will mean two different methods of gathering data. I also haven't yet got around to working out which values I need (probably only local ones?), analysing the performance cost of actually gathering them & then serialising them and implementing the value redacting system (ie passwords) sentry demands if you upload these things.