Merge pull request #1108 from lightpanda-io/wpt_panic_handler
Some checks failed
e2e-test / zig build release (push) Has been cancelled
e2e-test / demo-scripts (push) Has been cancelled
e2e-test / cdp-and-hyperfine-bench (push) Has been cancelled
e2e-test / perf-fmt (push) Has been cancelled
zig-test / zig build dev (push) Has been cancelled
zig-test / browser fetch (push) Has been cancelled
zig-test / zig test (push) Has been cancelled
zig-test / perf-fmt (push) Has been cancelled

Add custom panic handler to printt which file caused a panic
This commit is contained in:
Karl Seguin
2025-10-01 15:04:24 +08:00
committed by GitHub

View File

@@ -29,6 +29,9 @@ const TestHTTPServer = @import("TestHTTPServer.zig");
const WPT_DIR = "tests/wpt";
// use in custom panic handler
var current_test: ?[]const u8 = null;
pub fn main() !void {
var gpa: std.heap.DebugAllocator(.{}) = .init;
defer _ = gpa.deinit();
@@ -77,6 +80,9 @@ pub fn main() !void {
while (try it.next()) |test_file| {
defer _ = test_arena.reset(.retain_capacity);
defer current_test = null;
current_test = test_file;
var err_out: ?[]const u8 = null;
const result = run(
test_arena.allocator(),
@@ -448,3 +454,12 @@ fn httpHandler(req: *std.http.Server.Request) !void {
const file_path = try std.fmt.bufPrint(&buf, WPT_DIR ++ "{s}", .{path});
return TestHTTPServer.sendFile(req, file_path);
}
pub const panic = std.debug.FullPanic(struct {
pub fn panicFn(msg: []const u8, first_trace_addr: ?usize) noreturn {
if (current_test) |ct| {
std.debug.print("===panic running: {s}===\n", .{ct});
}
std.debug.defaultPanic(msg, first_trace_addr);
}
}.panicFn);