Error tracking for Control4 drivers
When a Control4 driver fails, Anvil records the line that failed, the handler that was running and the values in play, and groups it with every other time the same bug has happened.
Control4 drivers are Lua programs that run inside Director on a Control4 controller. There's no debugger attached to a controller, so when a driver throws an error, the Lua output window usually gives you one line and a line number in a bundled, often encrypted, file. Reproducing it means guessing what state the driver was in.
Anvil captures those errors for you. If you've used Sentry or Bugsnag on a web or mobile app, this is that kind of error tracking, built for drivers running on a Control4 controller. With the Driverforge SDK in your driver, every error raised in one of your handlers is recorded automatically, along with what you need to fix it:
- Where it failed. The function, file and line, with a full stack trace leading up to it.
- What was in play. The local variables in each frame at the moment of failure, and the arguments Director passed to your handler.
- How often it happens. Every occurrence of the same bug is grouped into one issue, so fifty identical errors show up as one problem with a count, and two different bugs with the same message stay separate.
- One report per error. An error that passes through several of your handlers on its way out is reported once.
- No surprises for the driver. Capture never changes what your driver sees: the original error is re-raised exactly as it would be without Anvil, and every capture is bounded so it can't strain the controller.
Errors outside a handler, such as in a timer callback, are captured too when you start the timer with Anvil:SetTimer. For anything else, Anvil:CaptureError records an error you've caught yourself.
The line that failed, with its values
Each captured frame carries the function name, the file and line, and the local variables in that function when the error was raised. Values are captured as real data, not formatted text: numbers stay numbers, tables keep their structure, and functions and userdata are recorded by type instead of as memory addresses. Known tables such as the global environment are recorded by name rather than walked.

Locals are where a trace can get large, so capture is bounded. Strings stop at 512 bytes and record how long the original was. That sits between the established tools: when we set the limit, Elastic APM kept 200 characters of a string value, Datadog 255 and Sentry 1,024. Tables are captured three levels deep and 20 entries wide, and a table that appears twice is recorded once and referenced after that. The trace as a whole has limits too, and a trace that reaches one is marked as partial, so you always know when you're seeing less than everything. The trade-off is that a limit will occasionally cut short the value you needed: the marker tells you how big it was, but not what was in it.
Grouped by where it happened
Grouping errors by their message goes wrong in both directions. Two unrelated timeouts share a message and get merged into one issue, while a single bug whose message includes a changing value, such as a temporary file path, splits into many.
Anvil groups by where the error happened instead: the error type and the top three frames of your code, using each frame's file, line and function. SDK frames and local variables are left out, so changing values never split a group. If a trace has no usable frames, Anvil falls back to the message, with numbers normalised.

Lines in your source, not the bundle
A built driver squishes your source files into one driver.lua, often encrypted, so even a correctly captured frame points at something like driver.lua.encrypted:415. Ask the Driverforge CLI for a source map when you build:
driverforge build --sourcemap
The map is written alongside the build and lets Anvil translate those lines back to your original files and line numbers.
How capture works
If you've ever tried to report errors from Lua yourself, the obvious approach is to wrap the call in pcall and call debug.traceback() when it fails. That trace is useless: by the time pcall returns, the stack has unwound, and the frames it shows belong to your reporting code.
xpcall is the fix. Its message handler runs at the point of failure, before the stack unwinds, so the failing function and its callers are still there to inspect. Anvil captures inside that handler, and guards the capture so it can never mask the error being reported: if capture itself fails, the trace is marked as such and your original error is re-raised unchanged.
When an error passes through several instrumented handlers, the innermost one reports it and tags it, and the outer ones pass it through untouched. The outermost unwraps the original error before handing it back to Director, so your driver sees exactly what it would without Anvil.
From an error to a fix
When an error comes in, you open one issue rather than fifty reports. It shows the line that failed, the stack that led there, the values in play and how often it has happened. Fix it in your editor, then deploy or sync the change to your controller. If the issue stops collecting new occurrences, the fix worked.

