1
0
Fork 0
mirror of https://github.com/portainer/portainer.git synced 2025-07-28 09:49:40 +02:00

fix(migration): bubble up recovered panic in new error EE-1971 (#5997)

* fix(migration): bubble up recovered panic in new error EE-1971

* improve code and add comments
This commit is contained in:
Matt Hook 2021-10-30 22:32:57 +13:00 committed by GitHub
parent 0caf5ca59e
commit 8f4589e535
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23

View file

@ -18,13 +18,16 @@ const beforePortainerVersionUpgradeBackup = "portainer.db.bak"
var migrateLog = plog.NewScopedLog("bolt, migrate") var migrateLog = plog.NewScopedLog("bolt, migrate")
// FailSafeMigrate backup and restore DB if migration fail // FailSafeMigrate backup and restore DB if migration fail
func (store *Store) FailSafeMigrate(migrator *migrator.Migrator) error { func (store *Store) FailSafeMigrate(migrator *migrator.Migrator) (err error) {
defer func() { defer func() {
if err := recover(); err != nil { if e := recover(); e != nil {
migrateLog.Info(fmt.Sprintf("Error during migration, recovering [%v]", err))
store.Rollback(true) store.Rollback(true)
err = fmt.Errorf("%v", e)
} }
}() }()
// !Important: we must use a named return value in the function definition and not a local
// !variable referenced from the closure or else the return value will be incorrectly set
return migrator.Migrate() return migrator.Migrate()
} }