Skip to content

Commit b0819ef

Browse files
authored
Place wrapper around comment as diff to catch panics (#15085) (#15086)
* Place wrapper around comment as diff to prevent panics * propagate the panic up Signed-off-by: Andrew Thornton <[email protected]>
1 parent d7a3bcd commit b0819ef

File tree

1 file changed

+10
-0
lines changed

1 file changed

+10
-0
lines changed

services/gitdiff/gitdiff.go

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1282,6 +1282,16 @@ func CommentAsDiff(c *models.Comment) (*Diff, error) {
12821282

12831283
// CommentMustAsDiff executes AsDiff and logs the error instead of returning
12841284
func CommentMustAsDiff(c *models.Comment) *Diff {
1285+
if c == nil {
1286+
return nil
1287+
}
1288+
defer func() {
1289+
if err := recover(); err != nil {
1290+
stack := log.Stack(2)
1291+
log.Error("PANIC whilst retrieving diff for comment[%d] Error: %v\nStack: %s", c.ID, err, stack)
1292+
panic(fmt.Errorf("PANIC whilst retrieving diff for comment[%d] Error: %v\nStack: %s", c.ID, err, stack))
1293+
}
1294+
}()
12851295
diff, err := CommentAsDiff(c)
12861296
if err != nil {
12871297
log.Warn("CommentMustAsDiff: %v", err)

0 commit comments

Comments
 (0)