From 6feb435867ed172e0e796b47c263b1191df765e9 Mon Sep 17 00:00:00 2001 From: zeripath Date: Sun, 21 Mar 2021 22:41:40 +0000 Subject: [PATCH] Place wrapper around comment as diff to catch panics (#15085) (#15094) Backport #15085 There are a few recurrent issues with comment as diff reporting panics that are resistant to fixing due to the fact that the panic occurs in the template render and is swallowed by the template renderer. This PR just adds some logging to force the panic to properly logged and re-propagates back up to the template renderer so we can actually detect what the issue is. Signed-off-by: Andrew Thornton art27@cantab.net --- services/gitdiff/gitdiff.go | 8 ++++++++ 1 file changed, 8 insertions(+) diff --git a/services/gitdiff/gitdiff.go b/services/gitdiff/gitdiff.go index 9f038c8744ee..8768b960fc33 100644 --- a/services/gitdiff/gitdiff.go +++ b/services/gitdiff/gitdiff.go @@ -1288,6 +1288,14 @@ func CommentAsDiff(c *models.Comment) (*Diff, error) { // CommentMustAsDiff executes AsDiff and logs the error instead of returning func CommentMustAsDiff(c *models.Comment) *Diff { + if c == nil { + return nil + } + defer func() { + if err := recover(); err != nil { + log.Error("PANIC whilst retrieving diff for comment[%d] Error: %v\nStack: %s", c.ID, err, log.Stack(2)) + } + }() diff, err := CommentAsDiff(c) if err != nil { log.Warn("CommentMustAsDiff: %v", err)