Garry's Mod Wiki

Revision Difference

GM:OnClientLuaError#564795

<function name="OnClientLuaError" parent="GM" type="hook"> <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 <page>GM:OnLuaError</page> for a hook that captures Lua errors directly within its [realm](States). </description>⤶ ⤶ <warning>Note that the stack argument can contain a table with 0 values. </warning>⤶ ⤶ </description>⤶ <realm>Server</realm> <added>2025.05.16</added> <args> <arg name="error" type="string">The error that occurred.</arg>⤶ <arg name="error" type="string">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>'⤶ </arg>⤶ <arg name="ply" type="Player">The player whose client caused the error.</arg> <arg name="stack" type="table">The Lua error stack trace</arg> <arg name="name" type="string">Title of the addon that is creating the Lua errors, or "ERROR" if addon is not found.</arg> </args> </function></function>⤶ ⤶ <example>⤶ <description>Example of a hook to retrieve clients errors</description>⤶ <code>⤶ 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)⤶ </code>⤶ ⤶ <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>'⤶ ⤶ ⤶ ```⤶ </output>⤶ ⤶ ⤶ </example>