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 {
|
if !ok {
|
||||||
rollbackErr := tx.Rollback()
|
rollbackErr := tx.Rollback()
|
||||||
if rollbackErr != nil {
|
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{})
|
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 {
|
if execErr != nil {
|
||||||
rollbackErr := tx.Rollback()
|
rollbackErr := tx.Rollback()
|
||||||
if rollbackErr != nil {
|
if rollbackErr != nil {
|
||||||
log.Println("rollback error ", rollbackErr)
|
log.Println("failed to rollback ", rollbackErr)
|
||||||
}
|
}
|
||||||
return execErr
|
return execErr
|
||||||
}
|
}
|
||||||
@ -63,7 +63,7 @@ func (repository BiteRepository) Create(headerID int64, models []interface{}) er
|
|||||||
if checkHeaderErr != nil {
|
if checkHeaderErr != nil {
|
||||||
rollbackErr := tx.Rollback()
|
rollbackErr := tx.Rollback()
|
||||||
if rollbackErr != nil {
|
if rollbackErr != nil {
|
||||||
log.Println("rollback error ", rollbackErr)
|
log.Println("failed to rollback ", rollbackErr)
|
||||||
}
|
}
|
||||||
return checkHeaderErr
|
return checkHeaderErr
|
||||||
}
|
}
|
||||||
|
@ -19,6 +19,7 @@ import (
|
|||||||
"github.com/vulcanize/vulcanizedb/pkg/datastore/postgres"
|
"github.com/vulcanize/vulcanizedb/pkg/datastore/postgres"
|
||||||
"github.com/vulcanize/vulcanizedb/pkg/transformers/shared"
|
"github.com/vulcanize/vulcanizedb/pkg/transformers/shared"
|
||||||
"github.com/vulcanize/vulcanizedb/pkg/transformers/shared/constants"
|
"github.com/vulcanize/vulcanizedb/pkg/transformers/shared/constants"
|
||||||
|
"log"
|
||||||
)
|
)
|
||||||
|
|
||||||
type CatFileChopLumpRepository struct {
|
type CatFileChopLumpRepository struct {
|
||||||
@ -26,33 +27,42 @@ type CatFileChopLumpRepository struct {
|
|||||||
}
|
}
|
||||||
|
|
||||||
func (repository CatFileChopLumpRepository) Create(headerID int64, models []interface{}) error {
|
func (repository CatFileChopLumpRepository) Create(headerID int64, models []interface{}) error {
|
||||||
tx, err := repository.db.Begin()
|
tx, dBaseErr := repository.db.Begin()
|
||||||
if err != nil {
|
if dBaseErr != nil {
|
||||||
return err
|
return dBaseErr
|
||||||
}
|
}
|
||||||
|
|
||||||
for _, model := range models {
|
for _, model := range models {
|
||||||
chopLump, ok := model.(CatFileChopLumpModel)
|
chopLump, ok := model.(CatFileChopLumpModel)
|
||||||
if !ok {
|
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{})
|
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)
|
`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)`,
|
VALUES($1, $2, $3, $4::NUMERIC, $5, $6, $7)`,
|
||||||
headerID, chopLump.Ilk, chopLump.What, chopLump.Data, chopLump.TransactionIndex, chopLump.LogIndex, chopLump.Raw,
|
headerID, chopLump.Ilk, chopLump.What, chopLump.Data, chopLump.TransactionIndex, chopLump.LogIndex, chopLump.Raw,
|
||||||
)
|
)
|
||||||
if err != nil {
|
if execErr != nil {
|
||||||
tx.Rollback()
|
rollbackErr := tx.Rollback()
|
||||||
return err
|
if rollbackErr != nil {
|
||||||
|
log.Println("failed to rollback ", rollbackErr)
|
||||||
|
}
|
||||||
|
return execErr
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
err = shared.MarkHeaderCheckedInTransaction(headerID, tx, constants.CatFileChopLumpChecked)
|
checkHeaderErr := shared.MarkHeaderCheckedInTransaction(headerID, tx, constants.CatFileChopLumpChecked)
|
||||||
if err != nil {
|
if checkHeaderErr != nil {
|
||||||
tx.Rollback()
|
rollbackErr := tx.Rollback()
|
||||||
return err
|
if rollbackErr != nil {
|
||||||
|
log.Println("failed to rollback ", rollbackErr)
|
||||||
|
}
|
||||||
|
return checkHeaderErr
|
||||||
}
|
}
|
||||||
return tx.Commit()
|
return tx.Commit()
|
||||||
}
|
}
|
||||||
|
Loading…
Reference in New Issue
Block a user