From aca10158456f98dcfda39778b37bbd7295d5d250 Mon Sep 17 00:00:00 2001 From: Darren McCleary Date: Tue, 12 Nov 2019 10:48:51 -0500 Subject: [PATCH] Log the panic message even if it's not of type error (#237) --- server/kit/kitserver.go | 11 +++++------ 1 file changed, 5 insertions(+), 6 deletions(-) diff --git a/server/kit/kitserver.go b/server/kit/kitserver.go index 3d7486eaf..f28f66014 100644 --- a/server/kit/kitserver.go +++ b/server/kit/kitserver.go @@ -161,12 +161,7 @@ func NewServer(svc Service) *Server { func (s *Server) ServeHTTP(w http.ResponseWriter, r *http.Request) { defer func() { if x := recover(); x != nil { - var err error - if e, ok := x.(error); ok { - err = e - } - - s.logger.Log("error", err, "message", "the server encountered a panic", "stacktrace", string(debug.Stack())) + s.logger.Log("error", x, "message", "the server encountered a panic", "stacktrace", string(debug.Stack())) w.WriteHeader(http.StatusInternalServerError) _, werr := w.Write([]byte(http.StatusText(http.StatusInternalServerError))) @@ -179,6 +174,10 @@ func (s *Server) ServeHTTP(w http.ResponseWriter, r *http.Request) { return } + var err error + if e, ok := x.(error); ok { + err = e + } s.errs.Report(errorreporting.Entry{ Req: r, Error: err,