Skip to content

Commit c891322

Browse files
authored
Merge pull request #1108 from lightpanda-io/wpt_panic_handler
Add custom panic handler to printt which file caused a panic
2 parents c335a54 + 69b65db commit c891322

File tree

1 file changed

+15
-0
lines changed

1 file changed

+15
-0
lines changed

src/main_wpt.zig

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -29,6 +29,9 @@ const TestHTTPServer = @import("TestHTTPServer.zig");
2929

3030
const WPT_DIR = "tests/wpt";
3131

32+
// use in custom panic handler
33+
var current_test: ?[]const u8 = null;
34+
3235
pub fn main() !void {
3336
var gpa: std.heap.DebugAllocator(.{}) = .init;
3437
defer _ = gpa.deinit();
@@ -77,6 +80,9 @@ pub fn main() !void {
7780
while (try it.next()) |test_file| {
7881
defer _ = test_arena.reset(.retain_capacity);
7982

83+
defer current_test = null;
84+
current_test = test_file;
85+
8086
var err_out: ?[]const u8 = null;
8187
const result = run(
8288
test_arena.allocator(),
@@ -448,3 +454,12 @@ fn httpHandler(req: *std.http.Server.Request) !void {
448454
const file_path = try std.fmt.bufPrint(&buf, WPT_DIR ++ "{s}", .{path});
449455
return TestHTTPServer.sendFile(req, file_path);
450456
}
457+
458+
pub const panic = std.debug.FullPanic(struct {
459+
pub fn panicFn(msg: []const u8, first_trace_addr: ?usize) noreturn {
460+
if (current_test) |ct| {
461+
std.debug.print("===panic running: {s}===\n", .{ct});
462+
}
463+
std.debug.defaultPanic(msg, first_trace_addr);
464+
}
465+
}.panicFn);

0 commit comments

Comments
 (0)