Closed hi10drasingh closed 2 years ago
something like this
// on package level
var ErrPanic = errors.New("PANIC")
// in your code
if rec := recover(); rec != nil {
trace := debug.Stack()
err = fmt.Errorf("[%v] TRACE[%s]: %w", rec, string(trace), ErrPanic)
}
BTW, you do not need error for panic.
Thanks, it worked!
The above code was from a recovery middleware on top of a rest server, that middleware will catch any handler panic and send panic with trace to the outer handler that will log error and will send 500 to the client without breaking the server
How to make panic errors wrapped static
linter error