aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorzeripath2021-03-21 15:16:07 +0000
committerGitHub2021-03-21 16:16:07 +0100
commitb0819efaeae1fb03a199d936af4cc475e71fcaf7 (patch)
tree6939db1ed5d2dda432ea4dfd7c05e37166890e0d
parentd7a3bcdd70bf9152ea5a153cb1dd9d0c370e4792 (diff)
Place wrapper around comment as diff to catch panics (#15085) (#15086)v1.13.5
* Place wrapper around comment as diff to prevent panics * propagate the panic up Signed-off-by: Andrew Thornton <art27@cantab.net>
-rw-r--r--services/gitdiff/gitdiff.go10
1 files changed, 10 insertions, 0 deletions
diff --git a/services/gitdiff/gitdiff.go b/services/gitdiff/gitdiff.go
index beb75c05e..0d95817a4 100644
--- a/services/gitdiff/gitdiff.go
+++ b/services/gitdiff/gitdiff.go
@@ -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)