diff options
author | zeripath <art27@cantab.net> | 2020-10-24 00:46:35 +0100 |
---|---|---|
committer | GitHub <noreply@github.com> | 2020-10-23 19:46:35 -0400 |
commit | f40a2a4404e3eabf5e28ae43e1f395bb13176307 (patch) | |
tree | e4c0ece7b11704eba0e9e60cb10158dbb5399db8 /modules | |
parent | 9b11c3e32037a77e53551127d26dbf54139aa2fc (diff) | |
download | gitea-f40a2a4404e3eabf5e28ae43e1f395bb13176307.tar.gz gitea-f40a2a4404e3eabf5e28ae43e1f395bb13176307.zip |
Store task errors following migrations and display them (#13246)
* Store task errors following migrations and display them
When migrate tasks fail store the error in the task table
and ensure that they show on the status page.
Fix #13242
Signed-off-by: Andrew Thornton <art27@cantab.net>
* Update web_src/js/index.js
* Hide the failed first
Signed-off-by: Andrew Thornton <art27@cantab.net>
Co-authored-by: techknowlogick <techknowlogick@gitea.io>
Diffstat (limited to 'modules')
-rw-r--r-- | modules/task/migrate.go | 39 |
1 files changed, 22 insertions, 17 deletions
diff --git a/modules/task/migrate.go b/modules/task/migrate.go index d25decaa00..99f0435b28 100644 --- a/modules/task/migrate.go +++ b/modules/task/migrate.go @@ -20,7 +20,7 @@ import ( "code.gitea.io/gitea/modules/util" ) -func handleCreateError(owner *models.User, err error, name string) error { +func handleCreateError(owner *models.User, err error) error { switch { case models.IsErrReachLimitOfRepo(err): return fmt.Errorf("You have already reached your limit of %d repositories", owner.MaxCreationLimit()) @@ -38,8 +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 { - 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) + err = fmt.Errorf("PANIC whilst trying to do migrate task: %v", e) + log.Critical("PANIC during runMigrateTask[%d] by DoerID[%d] to RepoID[%d] for OwnerID[%d]: %v\nStacktrace: %v", t.ID, t.DoerID, t.RepoID, t.OwnerID, e, log.Stack(2)) } if err == nil { @@ -55,7 +55,8 @@ func runMigrateTask(t *models.Task) (err error) { t.EndTime = timeutil.TimeStampNow() t.Status = structs.TaskStatusFailed t.Errors = err.Error() - if err := t.UpdateCols("status", "errors", "end_time"); err != nil { + t.RepoID = 0 + if err := t.UpdateCols("status", "errors", "repo_id", "end_time"); err != nil { log.Error("Task UpdateCols failed: %v", err) } @@ -66,8 +67,8 @@ func runMigrateTask(t *models.Task) (err error) { } }() - if err := t.LoadRepo(); err != nil { - return err + if err = t.LoadRepo(); err != nil { + return } // if repository is ready, then just finsih the task @@ -75,33 +76,35 @@ func runMigrateTask(t *models.Task) (err error) { return nil } - if err := t.LoadDoer(); err != nil { - return err + if err = t.LoadDoer(); err != nil { + return } - if err := t.LoadOwner(); err != nil { - return err + if err = t.LoadOwner(); err != nil { + return } t.StartTime = timeutil.TimeStampNow() t.Status = structs.TaskStatusRunning - if err := t.UpdateCols("start_time", "status"); err != nil { - return err + if err = t.UpdateCols("start_time", "status"); err != nil { + return } var opts *migration.MigrateOptions opts, err = t.MigrateConfig() if err != nil { - return err + return } opts.MigrateToRepoID = t.RepoID - repo, err := migrations.MigrateRepository(graceful.GetManager().HammerContext(), t.Doer, t.Owner.Name, *opts) + var repo *models.Repository + repo, err = migrations.MigrateRepository(graceful.GetManager().HammerContext(), t.Doer, t.Owner.Name, *opts) if err == nil { log.Trace("Repository migrated [%d]: %s/%s", repo.ID, t.Owner.Name, repo.Name) - return nil + return } if models.IsErrRepoAlreadyExist(err) { - return errors.New("The repository name is already used") + err = errors.New("The repository name is already used") + return } // remoteAddr may contain credentials, so we sanitize it @@ -113,5 +116,7 @@ func runMigrateTask(t *models.Task) (err error) { return fmt.Errorf("Migration failed: %v", err.Error()) } - return handleCreateError(t.Owner, err, "MigratePost") + // do not be tempted to coalesce this line with the return + err = handleCreateError(t.Owner, err) + return } |