From ddf4fb9efa4cc1d23f778f7f3de321266ec5a395 Mon Sep 17 00:00:00 2001 From: kim Date: Fri, 8 Jul 2022 08:42:10 +0100 Subject: [PATCH] panics get logged at error level, now include stacktrace Signed-off-by: kim --- internal/api/errorhandling.go | 10 +++++++++- 1 file changed, 9 insertions(+), 1 deletion(-) diff --git a/internal/api/errorhandling.go b/internal/api/errorhandling.go index 59b58bcc3..834f49ee8 100644 --- a/internal/api/errorhandling.go +++ b/internal/api/errorhandling.go @@ -22,6 +22,7 @@ import ( "context" "net/http" + "codeberg.org/gruf/go-errors/v2" "github.com/gin-gonic/gin" "github.com/sirupsen/logrus" apimodel "github.com/superseriousbusiness/gotosocial/internal/api/model" @@ -107,7 +108,14 @@ func ErrorHandler(c *gin.Context, errWithCode gtserror.WithCode, instanceGet fun // we should still try to return a basic code defer func() { if p := recover(); p != nil { - l.Warnf("recovered from panic: %s", p) + // Fetch stacktrace up to this point + callers := errors.GetCallers(3, 10) + + // Log this panic to the standard log + l = l.WithField("stacktrace", callers) + l.Errorf("recovered from panic: %v", p) + + // Respond with determined error code c.JSON(statusCode, gin.H{"error": errWithCode.Safe()}) } }()