Skip to content

Commit

Permalink
Merge pull request #96 from hellofresh/hotfix/small-improvements
Browse files Browse the repository at this point in the history
Fix typo and improve error handling
  • Loading branch information
mereba authored Mar 16, 2018
2 parents 090eb93 + 8e70a96 commit ac1b47e
Show file tree
Hide file tree
Showing 3 changed files with 13 additions and 7 deletions.
2 changes: 1 addition & 1 deletion pkg/dumper/dumper.go
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ type (
NewConnection(ConnOpts, reader.Reader) (Dumper, error)
}

// A Dumper writes a database's stucture to the provided stream.
// A Dumper writes a database's structure to the provided stream.
Dumper interface {
// Dump executes the dump process.
Dump(chan<- struct{}, *config.Spec, int) error
Expand Down
8 changes: 5 additions & 3 deletions pkg/dumper/mysql/dumper.go
Original file line number Diff line number Diff line change
Expand Up @@ -54,10 +54,12 @@ func (d *myDumper) DumpTable(tableName string, rowChan <-chan database.Row) erro

insertedRows, err := d.insertIntoTable(txn, tableName, rowChan)
if err != nil {
defer func() {
if err := txn.Rollback(); err != nil {
log.WithError(err).Error("failed to rollback")
}
}()
err = errors.Wrap(err, "failed to insert rows")
if err := txn.Rollback(); err != nil {
return errors.Wrap(err, "failed to rollback transaction")
}
return err
}

Expand Down
10 changes: 7 additions & 3 deletions pkg/dumper/postgres/dumper.go
Original file line number Diff line number Diff line change
Expand Up @@ -48,11 +48,15 @@ func (d *pgDumper) DumpTable(tableName string, rowChan <-chan database.Row) erro

insertedRows, err := d.insertIntoTable(txn, tableName, rowChan)
if err != nil {
defer func() {
if err := txn.Rollback(); err != nil {
log.WithError(err).Error("failed to rollback")
}
}()
err = errors.Wrap(err, "failed to insert rows")
if err := txn.Rollback(); err != nil {
return errors.Wrap(err, "failed to rollback transaction")
}
return err
}

log.WithFields(log.Fields{
"table": tableName,
"inserted": insertedRows,
Expand Down

0 comments on commit ac1b47e

Please sign in to comment.