Skip to content

Commit

Permalink
Log the underlying panic in runMigrateTask (go-gitea#13096)
Browse files Browse the repository at this point in the history
If there is a panic during runMigrateTask we should capture and log the underlying
panic error.

This PR ensures that the panic is logged and captured as part of the task message.

Fix go-gitea#13095

Signed-off-by: Andrew Thornton <art27@cantab.net>
  • Loading branch information
zeripath committed Oct 11, 2020
1 parent 170b57f commit 75a1ae6
Showing 1 changed file with 4 additions and 7 deletions.
11 changes: 4 additions & 7 deletions modules/task/migrate.go
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,6 @@
package task

import (
"bytes"
"errors"
"fmt"
"strings"
Expand Down Expand Up @@ -39,10 +38,8 @@ func handleCreateError(owner *models.User, err error, name string) error {
func runMigrateTask(t *models.Task) (err error) {
defer func() {
if e := recover(); e != nil {
var buf bytes.Buffer
fmt.Fprintf(&buf, "Handler crashed with error: %v", log.Stack(2))

err = errors.New(buf.String())
err = fmt.Errorf("PANIC whilst trying to do migrate task: %v\nStacktrace: %v", err, log.Stack(2))
log.Critical("PANIC during runMigrateTask[%d] by DoerID[%d] to RepoID[%d] for OwnerID[%d]: %v", t.ID, t.DoerID, t.RepoID, t.OwnerID, err)
}

if err == nil {
Expand All @@ -52,14 +49,14 @@ func runMigrateTask(t *models.Task) (err error) {
return
}

log.Error("FinishMigrateTask failed: %s", err.Error())
log.Error("FinishMigrateTask[%d] by DoerID[%d] to RepoID[%d] for OwnerID[%d] failed: %v", t.ID, t.DoerID, t.RepoID, t.OwnerID, err)
}

t.EndTime = timeutil.TimeStampNow()
t.Status = structs.TaskStatusFailed
t.Errors = err.Error()
if err := t.UpdateCols("status", "errors", "end_time"); err != nil {
log.Error("Task UpdateCols failed: %s", err.Error())
log.Error("Task UpdateCols failed: %v", err)
}

if t.Repo != nil {
Expand Down

0 comments on commit 75a1ae6

Please sign in to comment.