--- /dev/null
+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()))
+ }
+}
"net"
"os"
"path/filepath"
- "runtime/debug"
"strings"
"sync"
"time"
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)