Don't Trip[wire] Yourself: Testing Error Recovery in Zig
9 hours ago
- - Mitchell Hashimoto wrote Tripwire, a Zig library for injecting failures to test error recovery, which is optimized away outside tests with zero runtime cost.
- - Zig's `errdefer` runs code on block exit only when an error is returned, but testing error codepaths is difficult due to low execution frequency.
- - Tripwire allows named failure points in code, enabling tests to trigger specific errors and verify `errdefer` cleanup via tools like `std.testing.allocator` to detect leaks.
- - The library uses `comptime` to detect test builds, making checks zero-cost (no memory or machine code) in release builds.
- - Integration into Ghostty uncovered ~6 `errdefer` bugs, which were fixed with tests to prevent regression.