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)