From 69b65dbd41a863c76ac5aa96be64f066d25fe087 Mon Sep 17 00:00:00 2001 From: Karl Seguin Date: Wed, 1 Oct 2025 11:24:41 +0800 Subject: [PATCH] Add custom panic handler to printt which file caused a panic --- src/main_wpt.zig | 15 +++++++++++++++ 1 file changed, 15 insertions(+) diff --git a/src/main_wpt.zig b/src/main_wpt.zig index 161645b1..4d509f46 100644 --- a/src/main_wpt.zig +++ b/src/main_wpt.zig @@ -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);