From a9bdccb79164a787b4f1a2c1579a95cf751aef40 Mon Sep 17 00:00:00 2001 From: Jeff Halter <868228+jhalter@users.noreply.github.com> Date: Sun, 3 Jul 2022 15:09:20 -0700 Subject: Move panic handler --- hotline/panic.go | 15 +++++++++++++++ 1 file changed, 15 insertions(+) create mode 100644 hotline/panic.go (limited to 'hotline/panic.go') diff --git a/hotline/panic.go b/hotline/panic.go new file mode 100644 index 0000000..e7c97db --- /dev/null +++ b/hotline/panic.go @@ -0,0 +1,15 @@ +package hotline + +import ( + "fmt" + "go.uber.org/zap" + "runtime/debug" +) + +// dontPanic logs panics instead of crashing +func dontPanic(logger *zap.SugaredLogger) { + if r := recover(); r != nil { + fmt.Println("stacktrace from panic: \n" + string(debug.Stack())) + logger.Errorw("PANIC", "err", r, "trace", string(debug.Stack())) + } +} -- cgit