Skip to content
Snippets Groups Projects
Commit 80944a01 authored by Christian Pointner's avatar Christian Pointner
Browse files

fix error handling and rollback

parent d661fd42
No related branches found
No related tags found
No related merge requests found
......@@ -63,6 +63,7 @@ func (st *Store) UpdateFile(show string, id uint64, file File) (*File, error) {
defer func() {
if r := recover(); r != nil {
tx.Rollback()
// TODO: make sure to return non-nil err !!!
}
}()
if err := tx.Error; err != nil {
......@@ -91,6 +92,7 @@ func (st *Store) UpdateFileMetadata(show string, id uint64, metadata map[string]
defer func() {
if r := recover(); r != nil {
tx.Rollback()
// TODO: make sure to return non-nil err !!!
}
}()
if err := tx.Error; err != nil {
......
......@@ -109,6 +109,7 @@ func (st *Store) UpdatePlaylist(show string, id uint64, playlist Playlist) (*Pla
defer func() {
if r := recover(); r != nil {
tx.Rollback()
// TODO: make sure to return non-nil err !!!
}
}()
if err := tx.Error; err != nil {
......
......@@ -26,6 +26,7 @@ package store
import (
"errors"
"fmt"
"os"
"path/filepath"
......@@ -49,7 +50,7 @@ func (st *Store) createShow(tx *gorm.DB, name string) (show *Show, err error) {
}
}
show = &Show{Name: name}
err = st.db.FirstOrCreate(show).Error
err = tx.FirstOrCreate(show).Error
return
}
......@@ -76,7 +77,7 @@ func (st *Store) cloneFiles(tx *gorm.DB, name, from string) (err error) {
}
// TODO: also clone import logs
}
return nil
return
}
func (st *Store) clonePlaylists(tx *gorm.DB, name, from string) error {
......@@ -92,6 +93,10 @@ func (st *Store) CloneShow(name, from string) (show *Show, err error) {
defer func() {
if r := recover(); r != nil {
tx.Rollback()
os.RemoveAll(st.getShowPath(name))
if err == nil {
err = fmt.Errorf("runtime panic: %+v", r)
}
}
}()
if err = tx.Error; err != nil {
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment