summaryrefslogtreecommitdiffstats
path: root/services
diff options
context:
space:
mode:
authorzeripath <art27@cantab.net>2021-03-21 16:59:58 +0000
committerGitHub <noreply@github.com>2021-03-21 16:59:58 +0000
commit46782d53bc2ad721cc0337417391d89748f37a5d (patch)
tree0ef0d6fe9322fc4d15baa38bcb7f3a4ceb52b41f /services
parent24f7bd589945c8fc22c9cfc00bc21fca679da9d0 (diff)
downloadgitea-46782d53bc2ad721cc0337417391d89748f37a5d.tar.gz
gitea-46782d53bc2ad721cc0337417391d89748f37a5d.zip
Place wrapper around comment as diff to catch panics (#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
Diffstat (limited to 'services')
-rw-r--r--services/gitdiff/gitdiff.go8
1 files changed, 8 insertions, 0 deletions
diff --git a/services/gitdiff/gitdiff.go b/services/gitdiff/gitdiff.go
index 9f038c8744..8768b960fc 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)