Garry's Mod Wiki

GM:OnClientLuaError

  GM:OnClientLuaError( string error, Player ply, table stack, string name )

Recently Added

This was recently added in version (2025.05.16). It might only be available on the Dev Branch right now.

Description

Called on the server when a Lua error occurs on a client and is sent to the server.

This hook allows server-side code to detect and log client-side errors.

See GM:OnLuaError for a hook that captures Lua errors directly within its realm.

Note that the stack argument can contain a table with 0 values.
Warning: the hook "protects" against lua error spam. If it has 5 errors in less than 1 second, the hook will not receive any of these 4 errors.

Arguments

1 string error
The error that occurred. As well as the path and line of the error. Example : addons/test/lua/autorun/client/test_error.lua:4: 'then' expected near '<eof>'
2 Player ply
The player whose client caused the error.
3 table stack
The Lua error stack trace
4 string name
Title of the addon that is creating the Lua errors, or "ERROR" if addon is not found.

Example

Example of a hook to retrieve clients errors

hook.Add("OnClientLuaError", "Test", function(sError, pPlayer, tStack, sNameAddon) print("tStack:") PrintTable(tStack) print("The player " .. (IsValid(pPlayer) and pPlayer:Nick() or "unknown") .. " has encountered an error in addon '" .. sNameAddon .. "' : " .. sError) end)
Output:
-- The “error” function is used to generate tStack: [1]: ["File"] = [C] ["Function"] = error ["Line"] = -1 [2]: ["File"] = addons/test/lua/autorun/client/test_error.lua ["Function"] = ["Line"] = 3 The player Vitroze_Gaming has encountered an error in addon 'test' : addons/test/lua/autorun/client/test_error.lua:3: This is a test for the hook. Generated by the error function -- A syntax error is generated tStack: (No Value) The player Vitroze_Gaming has encountered an error in addon 'test' : addons/test/lua/autorun/client/test_error.lua:4: 'then' expected near '<eof>'