Giter VIP home page Giter VIP logo

gm_luaerror's Introduction

gm_luaerror

Build Status

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).

API reference

luaerror.Version -- holds the luaerror module version in a string form
luaerror.VersionNum -- holds the luaerror module version in a numeric form, LuaJIT style

luaerror.EnableRuntimeDetour(boolean) -- enable/disable Lua runtime errors
luaerror.EnableCompiletimeDetour(boolean) -- enable/disable Lua compiletime errors

luaerror.EnableClientDetour(boolean) -- enable/disable Lua errors from clients (serverside only)
-- returns nil followed by an error string in case of failure to detour

Hooks:
LuaError(isruntime, fullerror, sourcefile, sourceline, errorstr, stack)
-- isruntime is a boolean saying whether this is a runtime error or not
-- fullerror is a string which is the full error
-- sourcefile is a string which is the source file of the error
-- sourceline is a number which is the source line of the error
-- errorstr is a string which is the error itself
-- stack is a table containing the Lua stack at the time of the error

ClientLuaError(player, fullerror, sourcefile, sourceline, errorstr, stack)
-- player is a Player object which indicates who errored
-- fullerror is a string which is the full error (trimmed and cleaned up)
-- sourcefile is a string which is the source file of the error (may be nil)
-- sourceline is a number which is the source line of the error (may be nil)
-- errorstr is a string which is the error itself (may be nil)
-- stack is a table containing the Lua stack at the time of the error
-- sourcefile, sourceline and errorstr may be nil because of ErrorNoHalt and friends

Compiling

The only supported compilation platform for this project on Windows is Visual Studio 2017 on release mode. However, it's possible it'll work with Visual Studio 2015 and Visual Studio 2019 because of the unified runtime.

On Linux, everything should work fine as is, on release mode.

For macOS, any Xcode (using the GCC compiler) version MIGHT work as long as the Mac OSX 10.7 SDK is used, on release mode.

These restrictions are not random; they exist because of ABI compatibility reasons.

If stuff starts erroring or fails to work, be sure to check the correct line endings (\n and such) are present in the files for each OS.

Requirements

This project requires garrysmod_common, a framework to facilitate the creation of compilations files (Visual Studio, make, XCode, etc). Simply set the environment variable GARRYSMOD_COMMON or the premake option --gmcommon=path to the path of your local copy of garrysmod_common.

We also use SourceSDK2013. The links to SourceSDK2013 point to my own fork of VALVe's repo and for good reason: Garry's Mod has lots of backwards incompatible changes to interfaces and it's much smaller, being perfect for automated build systems like Azure Pipelines (which is used for this project).

gm_luaerror's People

Contributors

danielga avatar lexicality avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar  avatar

gm_luaerror's Issues

Direct access to the error's stack?

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.

Module is unable to create a hook for CL errors

If you attempt to require() the module in any situation with srcds, you'll get the following error stack -

[ERROR] unable to create a hook for HandleClientLuaError
  1. unknown - [C]:-1
   2. require - [C]:-1
    3. unknown - lua/autorun/server/luaerrortest.lua:1

Contents to reproduce is literally require("luaerror") on its' own. This seems to propagate one of two issues - it'll either cause a bootloop or crash upon a reload of the map.

x86-64 bit compatibility

As the x64bit beta branch is increasing in popularity, it would be very useful to be able to actually use it, while keeping track of errors with your wonderful module!

I personally have no experience with C++, so I really have no clue how difficult it would be, but I am hoping that it would become possible in the near future, as we plan to switch our servers onto the 64bit branch.

unable to create a hook for HandleClientLuaError

require "luaerror2"
unable to create a hook for HandleClientLuaError
1: (message = "unable to create a hook for HandleClientLuaError") [addons/gcompute/lua/gcompute/execution/local/gluaexecutioninstance.lua: 178]
2: ("d:\servers\garrysmod\garrysmod\lua\bin\gmsv_luaerror2_win32.dll", { table: 0x2d3df088 }, "unable to create a hook for HandleClientLuaError") [[C]: -1]
3: ("luaerror2", userdata: 0x2d3deef8) [[C]: -1]
4: (__param1 = "luaerror2") [[string "*"]: 0]
5: xpcall (function (message)) [[C]: -1]
6: Start (self = { GCompute.Execution.GLuaExecutionInstance: 0x2d3d91f0 }) [addons/gcompute/lua/gcompute/execution/local/gluaexecutioninstance.lua: 173]
7: CreateExecutionInstance (self = { GCompute.Execution.GLuaExecutionContext: 0x2d3c8668 }, code = "require "luaerror2"", sourceId = "@repl_0", instanceOptions = 6, callback = nil) [addons/gcompute/lua/gcompute/execution/executioncontext.lua: 56]
8: HandleExecutionInstanceCreationRequest0 (self = { GCompute.Execution.RemoteExecutionContextHost: 0x2d3ca0f8 }, connection = { GLib.Net.Connection: 0x2d3d4548 }, inBuffer = { GLib.Net.Layer1.PinnedNetInBuffer: 0x2d3d6f68 }) [addons/gcompute/lua/gcompute/execution/remote/remoteexecutioncontexthost.lua: 94]
9: (self = { GCompute.Execution.RemoteExecutionContextHost: 0x2d3ca0f8 }, connection = { GLib.Net.Connection: 0x2d3d4548 }, inBuffer = { GLib.Net.Layer1.PinnedNetInBuffer: 0x2d3d6f68 }) [addons/gcompute/lua/gcompute/execution/remote/remoteexecutioncontexthost.lua: 78]
10: xpcall (GLib.Error) [[C]: -1]
11: () [addons/glib/lua/glib/threading/thread.lua: 262]

Crash on Startup since latest GMod update (26/02/2018)

Getting a bootloop with this module loaded at startup.

Error as follows -

[ERROR] unable to sigscan function HandleClientLuaError
  1. unknown - [C]:-1
   2. require - [C]:-1
    3. unknown - snip
     4. include - [C]:-1
      5. IncludeServerFiles - snip
       6. unknown - snip
        7. include - [C]:-1
         8. unknown - snip
          9. DeriveGamemode - [C]:-1
           10. unknown -snip

Cleanup code and API

The hook argument count is getting massive and the code a little messy.

There's a great opportunity here to squash together the LuaError and ClientLuaError hooks into a single one which reports the source of the error with an enum for example. Maybe move all these arguments into a table as well.

These changes should bump the major version up since they're backwards incompatible.

Release Binaries

Would you be able to add some release binaries the the reop ( Win and Linux )? I'd love to use this lib but I have no idea how to build it.

"Unable to sigscan function HandleClientLuaError" on map change

Been finding out my server suddenly crashed the moment a map change happened, which seems to be related the moment another addon calls require("gm_luaerror"). For some reason, it does not affect it when the server process starts for the first time, only on map changes.

The server is running on the master branch.
The host machine runs on Windows Server 2019.

Module not loading on latest ubuntu version

Attempted to load this and wasn't working. I performed this test

require "luaerror"
hook.Add("LuaError","test", function(fullerror)
print("ooooof")
end)

It returned with

[ERROR] <color=255,100,100>LuaFoxx:1: Module not found!
stack traceback:
[C]: in function 'require'
<color=255,100,100>LuaFoxx:1: in main chunk
[C]: in function 'LUADEV_EXECUTE_FUNCTION'

Can't include module on linux 32 servers

I used the "gmsv_luaerror_linux.dll" and when using require("luaerror") when module placed in lua/bin/ it errors. When I down grade to the version from 2 years ago it now works.
Version: 1.5.3

Nothing is working?

I downloaded the cl version of the binary hoping to hide errors from the server somehow.
I required it in the client state not the menu state.

luaerror.EnableCompiletimeDetour(true) makes include think the file is empty or something.
I have tried having both of them false one true and both true.

Running script a.lua...
Couldn't include file 'a.lua' (File not found) ()

hook.Add("LuaError","heck",function(...)
print("oh no an error ",...)
end)
hook.Add("ClientLuaError","heck",hook.GetTable()["LuaError"]["heck"])

to trigger an error i am doing:
lua_run_cl -
lua_run_cl wat="
lua_run_cl local n n()

none of them print anything

Unable to sigscan function HandleClientLuaError

Tomorrow's GMod update includes changes to the C++ API and/or patches some exploits. At any rate, the update has broken the gmsv_luaerror module:

[ERROR] unable to sigscan function HandleClientLuaError
  1. unknown - [C]:-1
   2. require - [C]:-1
    3. unknown - addons/path/to/my/lua/file.lua:XX

I don't really know much beyond that. Simply require'ing the module will cause the error. I know myself and several others still rely on this module, so if you'd be willing to test out the prerelease branch today or the main branch when the update comes out tomorrow, we'd really appreciate it.

Crash with latest Garrysmod version

With the most recent release (2021.01.22), an error followed by a crash is recorded when using the latest luaerror.

[ERROR] unable to obtain AdvancedLuaErrorReporter
  1. unknown - [C]:-1
   2. require - [C]:-1

Linux Server Version doesn't work.

I just can't use gmsv_luaerror_linux.

lua_run print(pcall(require, "luaerror"))
> print(pcall(require, "luaerror"))...
false   Couldn't load module library!

Using gmcl_luaerror_linux works.
Can someone tell me why?

Runtime errors in autorun client scripts are wrongly considered compiletime

require("luaerror")

luaerror.EnableCompiletimeDetour(true)
luaerror.EnableRuntimeDetour(true)

if SERVER then
	luaerror.EnableClientDetour(true)

	hook.Add("ClientLuaError", "Test", function(ply, fullerr, filepath, line, errstr, errstack, addon)
		print(ply, fullerr, filepath, line, errstr, addon)
		PrintTable(errstack)
	end)
end

hook.Add("LuaError", "Test", function(isruntime, fullerr, filepath, line, errstr, errstack, addon)
	print(isruntime, fullerr, filepath, line, errstr, addon)
	PrintTable(errstack)
end)

RunString("failure")

local function he_actually_did_it()
	the_absolute_madman()
end

he_actually_did_it()

ClientLuaError stack missing `short_src`

Both hooks add the stack object, however they seem to be slightly different. I can't seem to get the short_src from the ClientLuaError hook stack at all.

Clientside example:
image
image

Serverside example:
image
image

Yet server side seems to have the short_src.

Might be intentional or just a limitation by gmod, in that case feel free to close it.

Last clientside error overrides server errors

] lua_run_cl error("cl err")

[ERROR] LuaCmd:1: cl err
  1. error - [C]:-1
   2. unknown - LuaCmd:1

[Lexi|10|STEAM_0:1:16678762] Lua Error:

[ERROR] LuaCmd:1: cl err
  1. error - [C]:-1
   2. unknown - LuaCmd:1


] lua_run error("sv err")
> error("sv err")...

[ERROR] lua_run:1: sv err
  1. error - [C]:-1
   2. unknown - lua_run:1

] lua_run luaerror.EnableCompiletimeDetour(true)
> luaerror.EnableCompiletimeDetour(true)...
] lua_run_cl error("cl err")

[ERROR] LuaCmd:1: cl err
  1. error - [C]:-1
   2. unknown - LuaCmd:1

[Lexi|10|STEAM_0:1:16678762] Lua Error:

[ERROR] LuaCmd:1: cl err
  1. error - [C]:-1
   2. unknown - LuaCmd:1


] lua_run error("sv err")
> error("sv err")...

[ERROR] lua_run:1: sv err
  1. error - [C]:-1
   2. unknown - lua_run:1

] lua_run luaerror.EnableRuntimeDetour(true)
> luaerror.EnableRuntimeDetour(true)...
] lua_run_cl error("cl err")

[ERROR] LuaCmd:1: cl err
  1. error - [C]:-1
   2. unknown - LuaCmd:1

[Lexi|10|STEAM_0:1:16678762] Lua Error:

[ERROR] LuaCmd:1: cl err
  1. error - [C]:-1
   2. unknown - LuaCmd:1


] lua_run error("sv err")
> error("sv err")...

[ERROR] LuaCmd:1: cl err
  1. error - [C]:-1
   2. unknown - lua_run:1

The stack trace is correct:

] lua_run function test2() error("what?") end function mytest() test2() end mytest()
> function test2() error("what?") end function mytest() test2() end mytest()...

[ERROR] LuaCmd:1: cl err
  1. error - [C]:-1
   2. test2 - lua_run:1
    3. mytest - lua_run:1
     4. unknown - lua_run:1

And the hook gets the right value:

] lua_run hook.Add("LuaError", "wut", function(_, e) print(e) end)
> hook.Add("LuaError", "wut", function(_, e) print(e) end)...
] lua_run error("sv err")
> error("sv err")...
lua_run:1: sv err

[ERROR] LuaCmd:1: cl err
  1. error - [C]:-1
   2. unknown - lua_run:1

linux version not throwing server errors

it just sends lua client errors even as both are detoured, the same code works fine on a srcds server running on windows.

tested both on debian and ubuntu server

recompile it to fix it dad

Segmentation fault on client error

Just started getting this recently. The first time a client receives an error with this module loaded, the server immediately segfaults.

Segmentation fault (core dumped)
Add "-debug" to the ./srcds_run command line to generate a debug.log to help with solving this problem

I know nothing about debugging but here's the initial output from gdb as per the guide here. I'm not sure how to get more valuable info from it.

Reading symbols from srcds_linux...
(No debugging symbols found in srcds_linux)
BFD: warning: /home/avtomat/serverfiles/core has a segment extending past end of file
[New LWP 3026220]
[New LWP 3027235]
[New LWP 3027234]
[New LWP 3027224]
[New LWP 3026223]
[New LWP 3026222]
[New LWP 3027222]
[New LWP 3026224]
[New LWP 3027226]
[New LWP 3027220]
[New LWP 3027236]
[New LWP 3026246]
--Type <RET> for more, q to quit, c to continue without paging--
[New LWP 3027229]
[New LWP 3027227]
[New LWP 3026247]
[New LWP 3026249]
[New LWP 3027230]
[New LWP 3026248]
[New LWP 3027219]
[New LWP 3026744]

warning: Error reading shared library list entry at 0x64646436
Cannot access memory at address 0x61353069
Cannot access memory at address 0x61353065
Failed to read a valid object file image from memory.
Core was generated by `./srcds_linux -game garrysmod -ip 0.0.0.0 -port 27016 +host_workshop_collection'.
Program terminated with signal SIGSEGV, Segmentation fault.
#0  0xf041b72e in ?? ()
[Current thread is 1 (LWP 3026220)]

No debug.log was generated.

Get which workshop addon is responsible?

When a workshop addon throws an error, the name of the addon is reported in the console like this:

[Kaboom - The Broken Addon] lua/autorun/server/boom.lua:1: this is an addon error

But this module reports it on its own:

lua/autorun/server/boom.lua:1: this is an addon error

The stack traces also lack any way of knowing what addon was responsible.
Is this fixable?
Thanks

Potential crash event with the latest GMod update

Exe build: 20:02:11 Dec 14 2021 (8438) (4000)
GMod version 2021.12.14, branch: unknown
Windows 32bit Dedicated Server

If an error is thrown before ISteamHTTP is available (e.g. close to or on server boot), the server will hang and endlessly consume RAM until the server echos not enough memory.

Example error trace:

[ERROR] HTTP failed - ISteamHTTP isn't available!
  1. Post - lua/includes/modules/http.lua:71
   2. v - gamemode/path/that/hooks
    3. unknown - lua/includes/modules/hook.lua:96
     4. HTTP - [C]:-1

Rare issue with determining the Source File and Source Line

While currently correct >99% of the time, it's technically possible to have a source file with a : in it.

The current implementation appears to split the string by all :'s, and assumes the first element is the File, and the second is the Line Number.

Instead, to cover all cases, it could split by only the last : and make the same assumptions.

"unable to obtain AdvancedLuaErrorReporter" when requiring module

As the title says, when I require("luaerror") I'm receiving the error in the title, alongside my server crashing immediately. Server is running on Windows Server 2019, GMod version is the latest version of the main branch. I am on the latest version of luaerror.

This only started happening after I updated the GMod server today (first time in around 3 months), if it helps.

My other installed modules:
https://github.com/Metastruct/gm_enginespew
https://github.com/FredyH/GWSockets
https://github.com/WilliamVenner/gmsv_reqwest

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.