]> git.r.bdr.sh - rbdr/mobius/commitdiff
Move panic handler
authorJeff Halter <redacted>
Sun, 3 Jul 2022 22:09:20 +0000 (15:09 -0700)
committerJeff Halter <redacted>
Sun, 3 Jul 2022 22:09:20 +0000 (15:09 -0700)
hotline/panic.go [new file with mode: 0644]
hotline/server.go

diff --git a/hotline/panic.go b/hotline/panic.go
new file mode 100644 (file)
index 0000000..e7c97db
--- /dev/null
@@ -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()))
+       }
+}
index 1fafb30b2a929ec28ebbd9e6d75ad9d2f925eb57..ccf992e2a68eeff39043055e3d7dc6f4861f2693 100644 (file)
@@ -18,7 +18,6 @@ import (
        "net"
        "os"
        "path/filepath"
-       "runtime/debug"
        "strings"
        "sync"
        "time"
@@ -542,14 +541,6 @@ func (s *Server) loadConfig(path string) error {
        return nil
 }
 
-// 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()))
-       }
-}
-
 // handleNewConnection takes a new net.Conn and performs the initial login sequence
 func (s *Server) handleNewConnection(ctx context.Context, rwc io.ReadWriteCloser, remoteAddr string) error {
        defer dontPanic(s.Logger)