]> source.dussan.org Git - gitea.git/commitdiff
Place wrapper around comment as diff to catch panics (#15085) (#15086) v1.13.5
authorzeripath <art27@cantab.net>
Sun, 21 Mar 2021 15:16:07 +0000 (15:16 +0000)
committerGitHub <noreply@github.com>
Sun, 21 Mar 2021 15:16:07 +0000 (16:16 +0100)
* Place wrapper around comment as diff to prevent panics

* propagate the panic up

Signed-off-by: Andrew Thornton <art27@cantab.net>
services/gitdiff/gitdiff.go

index beb75c05e869b618153cd4662c9904038512aebb..0d95817a44d05e977ffb8c52aad9d68021871ea8 100644 (file)
@@ -1282,6 +1282,16 @@ 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 {
+                       stack := log.Stack(2)
+                       log.Error("PANIC whilst retrieving diff for comment[%d] Error: %v\nStack: %s", c.ID, err, stack)
+                       panic(fmt.Errorf("PANIC whilst retrieving diff for comment[%d] Error: %v\nStack: %s", c.ID, err, stack))
+               }
+       }()
        diff, err := CommentAsDiff(c)
        if err != nil {
                log.Warn("CommentMustAsDiff: %v", err)