Files
bun.sh/src/panic_handler.zig
dave caruso 9e6e8b0234 feat(runtime): align import.meta.resolve with node.js's implementation (#5827)
* works

* works

* a

* fix zig compiler error

* fix things

* [autofix.ci] apply automated fixes

* a

* not done

* finish this

* [autofix.ci] apply automated fixes

* self check

* delete committed generated file (#9717)

* Fix bug with PipeWriter (#9714)

* fix!: do not lookup cwd in which (#9691)

* do not lookup cwd in which

* fix webkit submodule

* fix compilation on linux

* feedback

* default process.env.NODE_ENV to undefined (#9695)

* small changes

* [autofix.ci] apply automated fixes

* fix(windows) fix node-stream tests/ windows file reader/writer (#9718)

* fix canceled onFileRead

* report continue errors and fix closing

* also fix pipe writer

* avoid possible memory leaks

* Propagate errors in open

---------

Co-authored-by: Jarred Sumner <jarred@jarredsumner.com>

* posix failures

* windows fixes

* avoid using c++ labels

* add a resolver

* fix compile test AGAIN

---------

Co-authored-by: autofix-ci[bot] <114827586+autofix-ci[bot]@users.noreply.github.com>
Co-authored-by: Meghan Denny <hello@nektro.net>
Co-authored-by: Jarred Sumner <jarred@jarredsumner.com>
Co-authored-by: Ciro Spaciari <ciro.spaciari@gmail.com>
2024-04-01 02:21:34 -07:00

58 lines
2.0 KiB
Zig

const std = @import("std");
const bun = @import("root").bun;
const string = bun.string;
const Output = bun.Output;
const Global = bun.Global;
const Environment = bun.Environment;
const strings = bun.strings;
const MutableString = bun.MutableString;
const stringZ = bun.stringZ;
const default_allocator = bun.default_allocator;
const C = bun.C;
const CLI = @import("./cli.zig").Cli;
const Features = @import("./analytics/analytics_thread.zig").Features;
const HTTP = @import("root").bun.http.AsyncHTTP;
const Report = @import("./report.zig");
pub fn NewPanicHandler(comptime panic_func: fn ([]const u8, ?*std.builtin.StackTrace, ?usize) noreturn) type {
return struct {
panic_count: usize = 0,
skip_next_panic: bool = false,
log: *bun.logger.Log,
pub var Singleton: ?*Handler = null;
const Handler = @This();
pub fn init(log: *bun.logger.Log) Handler {
return Handler{
.log = log,
};
}
pub inline fn handle_panic(msg: []const u8, error_return_type: ?*std.builtin.StackTrace, addr: ?usize) noreturn {
// This exists to ensure we flush all buffered output before panicking.
Output.flush();
bun.maybeHandlePanicDuringProcessReload();
Report.fatal(null, msg);
Output.disableBuffering();
Output.Source.Stdio.restore();
if (bun.auto_reload_on_crash) {
// attempt to prevent a double panic
bun.auto_reload_on_crash = false;
Output.prettyErrorln("<d>--- Bun is auto-restarting due to crash <d>[time: <b>{d}<r><d>] ---<r>", .{@max(std.time.milliTimestamp(), 0)});
Output.flush();
bun.reloadProcess(bun.default_allocator, false);
}
// We want to always inline the panic handler so it doesn't show up in the stacktrace.
@call(bun.callmod_inline, panic_func, .{ msg, error_return_type, addr });
}
};
}