refactor error handling in chop_lump
This commit is contained in:
parent
78b302eab6
commit
513513e93b
@ -40,7 +40,7 @@ func (repository BiteRepository) Create(headerID int64, models []interface{}) er
|
||||
if !ok {
|
||||
rollbackErr := tx.Rollback()
|
||||
if rollbackErr != nil {
|
||||
log.Println("rollback error ", rollbackErr)
|
||||
log.Println("failed to rollback ", rollbackErr)
|
||||
}
|
||||
return fmt.Errorf("model of type %T, not %T", model, BiteModel{})
|
||||
}
|
||||
@ -53,7 +53,7 @@ func (repository BiteRepository) Create(headerID int64, models []interface{}) er
|
||||
if execErr != nil {
|
||||
rollbackErr := tx.Rollback()
|
||||
if rollbackErr != nil {
|
||||
log.Println("rollback error ", rollbackErr)
|
||||
log.Println("failed to rollback ", rollbackErr)
|
||||
}
|
||||
return execErr
|
||||
}
|
||||
@ -63,7 +63,7 @@ func (repository BiteRepository) Create(headerID int64, models []interface{}) er
|
||||
if checkHeaderErr != nil {
|
||||
rollbackErr := tx.Rollback()
|
||||
if rollbackErr != nil {
|
||||
log.Println("rollback error ", rollbackErr)
|
||||
log.Println("failed to rollback ", rollbackErr)
|
||||
}
|
||||
return checkHeaderErr
|
||||
}
|
||||
|
@ -19,6 +19,7 @@ import (
|
||||
"github.com/vulcanize/vulcanizedb/pkg/datastore/postgres"
|
||||
"github.com/vulcanize/vulcanizedb/pkg/transformers/shared"
|
||||
"github.com/vulcanize/vulcanizedb/pkg/transformers/shared/constants"
|
||||
"log"
|
||||
)
|
||||
|
||||
type CatFileChopLumpRepository struct {
|
||||
@ -26,33 +27,42 @@ type CatFileChopLumpRepository struct {
|
||||
}
|
||||
|
||||
func (repository CatFileChopLumpRepository) Create(headerID int64, models []interface{}) error {
|
||||
tx, err := repository.db.Begin()
|
||||
if err != nil {
|
||||
return err
|
||||
tx, dBaseErr := repository.db.Begin()
|
||||
if dBaseErr != nil {
|
||||
return dBaseErr
|
||||
}
|
||||
|
||||
for _, model := range models {
|
||||
chopLump, ok := model.(CatFileChopLumpModel)
|
||||
if !ok {
|
||||
tx.Rollback()
|
||||
rollbackErr := tx.Rollback()
|
||||
if rollbackErr != nil {
|
||||
log.Println("failed to rollback ", rollbackErr)
|
||||
}
|
||||
return fmt.Errorf("model of type %T, not %T", model, CatFileChopLumpModel{})
|
||||
}
|
||||
|
||||
_, err = tx.Exec(
|
||||
_, execErr := tx.Exec(
|
||||
`INSERT into maker.cat_file_chop_lump (header_id, ilk, what, data, tx_idx, log_idx, raw_log)
|
||||
VALUES($1, $2, $3, $4::NUMERIC, $5, $6, $7)`,
|
||||
headerID, chopLump.Ilk, chopLump.What, chopLump.Data, chopLump.TransactionIndex, chopLump.LogIndex, chopLump.Raw,
|
||||
)
|
||||
if err != nil {
|
||||
tx.Rollback()
|
||||
return err
|
||||
if execErr != nil {
|
||||
rollbackErr := tx.Rollback()
|
||||
if rollbackErr != nil {
|
||||
log.Println("failed to rollback ", rollbackErr)
|
||||
}
|
||||
return execErr
|
||||
}
|
||||
}
|
||||
|
||||
err = shared.MarkHeaderCheckedInTransaction(headerID, tx, constants.CatFileChopLumpChecked)
|
||||
if err != nil {
|
||||
tx.Rollback()
|
||||
return err
|
||||
checkHeaderErr := shared.MarkHeaderCheckedInTransaction(headerID, tx, constants.CatFileChopLumpChecked)
|
||||
if checkHeaderErr != nil {
|
||||
rollbackErr := tx.Rollback()
|
||||
if rollbackErr != nil {
|
||||
log.Println("failed to rollback ", rollbackErr)
|
||||
}
|
||||
return checkHeaderErr
|
||||
}
|
||||
return tx.Commit()
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user