database: panic on errors from Commit/Rollback The previous change would eat the error from fn(tx); in truth we should ensure that it is returned to the caller. This panics instead if an error occurs during Commit or Rollback. I'm not sure of what scenarios would cause this to occur, but they all probably deserve further investigation - a panic will raise it to our attention.
1 files changed, 8 insertions(+), 5 deletions(-) M database/middleware.go
M database/middleware.go => database/middleware.go +8 -5
@@ 61,12 61,15 @@ func WithTx(ctx context.Context, opts *sql.TxOptions, fn func(tx *sql.Tx) error) }() err = fn(tx) if err != nil { err = tx.Rollback() err := tx.Rollback() if err != nil && err != sql.ErrTxDone { panic(err) } } else { err = tx.Commit() } if err == sql.ErrTxDone { err = nil err := tx.Commit() if err != nil && err != sql.ErrTxDone { panic(err) } } return err }