Skip to content

Commit

Permalink
Add hook to queue event (#36)
Browse files Browse the repository at this point in the history
  • Loading branch information
brandonsturgeon committed Jan 15, 2024
1 parent 566609b commit 2f4b56c
Show file tree
Hide file tree
Showing 2 changed files with 51 additions and 2 deletions.
50 changes: 48 additions & 2 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ This addon will watch for errors, do a little investigation, and send a message
<br>

## Notice ⚠️
A full-rewrite of this addon is nearly complete. It has fixes, new features, and design reworks.
A full-rewrite of this addon is nearly complete. It has fixes, new features, design reworks, and will attempt to use the upcoming [`OnLuaError`](https://wiki.facepunch.com/gmod/GM:OnLuaError) hook.

Please keep an eye out for the update!

Expand Down Expand Up @@ -41,7 +41,6 @@ You can track its progress in our support Discord: https://discord.gg/5JUqZjzmYJ
- **`cfc_err_forwarder_client_webhook`**: The full Discord Webhook URL to send Clientside errors
- **`cfc_err_forwarder_client_enabled`**: A boolean indicating whether or not the addon should even track Clientside errors


## Screenshots

### Serverside Error with Locals and Context
Expand All @@ -50,3 +49,50 @@ You can track its progress in our support Discord: https://discord.gg/5JUqZjzmYJ

### Clientside Error with Context
![image](https://user-images.githubusercontent.com/7936439/188520586-fdd2f05f-c83a-458a-a7f3-8f29fa99b95f.png)

<br>

## Hooks

### `CFC_ErrorForwarder_PreQueue`
Called before an Error is queued to be processed.

Return `false` to prevent it from being queued.

You may also _(carefully)_ modify the error structure.

### Error Structure
With the following code:
```lua
-- addons/example/lua/example/init.lua
AddCSLuaFile()
if SERVER then return end

local function exampleFunction()
print( 5 + {} )
end

hook.Add( "InitPostEntity", "Example", function()
ProtectedCall( exampleFunction )
end )
```

The error structure would look like:
| **Name** | **Type** | **Example** | **Description** |
|------------------|-----------|----------------------------------------------------------------------|-------------------------------------------------------------------------------------------------------------------------------------------------------------------------|
| `branch` | `string` | `"unknown"` _(Base branch)_ | The game branch where the error occurred. Is either `"Not sure yet"` if the client errored early, or [`BRANCH`](https://wiki.facepunch.com/gmod/Global.BRANCH) string |
| `count` | `number` | `1` | How many times this error has occurred _(Will always be `1` in `CFC_ErrorForrwarder_PreQueue`)_ |
| `errorString` | `string` | `"attempt to perform arithmetic on a table value"` | The actual error message that was produced |
| `fullError` | `string` | | The full, raw, multiline error string with a simplified stack |
| `isClientside` | `boolean` | `true` | Whether or not this error occurred on a client |
| `isRuntime` | `boolean` | `true` | "Whether this is a runtime error or not" - taken straight from `gm_luaerror` |
| `occurredAt` | `number` | `1704534832` | The result of `os.time()` of when the error occurred |
| `ply` | `Player` | `Player [1][Phatso]` | The Player who experienced the error, or `nil` if serverside |
| `plyName` | `string` | `"Phatso"` | `nil` if serverside |
| `plySteamID` | `string` | `"STEAM_0:0:21170873"` | `nil` if serverside |
| `reportInterval` | `number` | `60` | In seconds, how often the addon is sending errors to Discord |
| `sourceFile` | `string` | `"addons/test/lua/example/init.lua"` | The file path where the error occurred |
| `sourceLine` | `number` | `4` | |
| `stack` | `table` | `{ 1 = { currentLine = 4, name = "unknown", source = "..." }, ... }` | A numerically indexed Stack object |


3 changes: 3 additions & 0 deletions moon/cfc_err_forwarder/error_forwarder.moon
Original file line number Diff line number Diff line change
Expand Up @@ -117,6 +117,9 @@ return class ErrorForwarder
if isClientside
newError = @addPlyToObject newError, ply

shouldQueue = hook.Run "CFC_ErrorForwarder_PreQueue", newError
return if shouldQueue == false

@logger\debug "Inserting error into queue: '#{fullError}'"

rawset @queue, fullError, newError
Expand Down

0 comments on commit 2f4b56c

Please sign in to comment.