Skip to content

Commit e9d917b

Browse files
committed
Place wrapper around comment as diff to catch panics (#15085)
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 [email protected]
1 parent d770cc9 commit e9d917b

File tree

1 file changed

+8
-0
lines changed

1 file changed

+8
-0
lines changed

services/gitdiff/gitdiff.go

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1288,6 +1288,14 @@ func CommentAsDiff(c *models.Comment) (*Diff, error) {
12881288

12891289
// CommentMustAsDiff executes AsDiff and logs the error instead of returning
12901290
func CommentMustAsDiff(c *models.Comment) *Diff {
1291+
if c == nil {
1292+
return nil
1293+
}
1294+
defer func() {
1295+
if err := recover(); err != nil {
1296+
log.Error("PANIC whilst retrieving diff for comment[%d] Error: %v\nStack: %s", c.ID, err, log.Stack(2))
1297+
}
1298+
}()
12911299
diff, err := CommentAsDiff(c)
12921300
if err != nil {
12931301
log.Warn("CommentMustAsDiff: %v", err)

0 commit comments

Comments
 (0)