Skip to content

Commit

Permalink
remove github.com/pkg/errors ref (#133)
Browse files Browse the repository at this point in the history
  • Loading branch information
lucasmdrs authored Sep 27, 2021
1 parent e246e46 commit 0305d85
Show file tree
Hide file tree
Showing 16 changed files with 62 additions and 71 deletions.
6 changes: 3 additions & 3 deletions cmd/init.go
Original file line number Diff line number Diff line change
@@ -1,9 +1,9 @@
package cmd

import (
"fmt"
"os"

wErrors "github.com/pkg/errors"
log "github.com/sirupsen/logrus"
"github.com/spf13/cobra"

Expand Down Expand Up @@ -34,11 +34,11 @@ func RunInit() error {

f, err := os.Create(config.DefaultConfigFileName)
if err != nil {
return wErrors.Wrap(err, "could not create file")
return fmt.Errorf("could not create file: %w", err)
}

if err := config.WriteSample(f); err != nil {
return wErrors.Wrap(err, "could not write config")
return fmt.Errorf("could not write config: %w", err)
}

log.Infof("Created %s!", config.DefaultConfigFileName)
Expand Down
8 changes: 4 additions & 4 deletions cmd/steal.go
Original file line number Diff line number Diff line change
@@ -1,10 +1,10 @@
package cmd

import (
"fmt"
"runtime"
"time"

wErrors "github.com/pkg/errors"
log "github.com/sirupsen/logrus"
"github.com/spf13/cobra"

Expand Down Expand Up @@ -90,7 +90,7 @@ func RunSteal(opts *StealOptions) (err error) {
MaxIdleConns: opts.readOpts.maxIdleConns,
})
if err != nil {
return wErrors.Wrap(err, "Could not connecting to reader")
return fmt.Errorf("could not connecting to reader: %w", err)
}
defer func() {
if err := source.Close(); err != nil {
Expand All @@ -108,7 +108,7 @@ func RunSteal(opts *StealOptions) (err error) {
MaxIdleConns: opts.writeOpts.maxIdleConns,
}, source)
if err != nil {
return wErrors.Wrap(err, "Error creating dumper")
return fmt.Errorf("error creating dumper: %w", err)
}
defer func() {
if err := target.Close(); err != nil {
Expand All @@ -123,7 +123,7 @@ func RunSteal(opts *StealOptions) (err error) {

start := time.Now()
if err := target.Dump(done, opts.cfgTables, opts.concurrency); err != nil {
return wErrors.Wrap(err, "Error while dumping")
return fmt.Errorf("error while dumping: %w", err)
}

<-done
Expand Down
5 changes: 2 additions & 3 deletions cmd/update.go
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,6 @@ import (

"github.com/hellofresh/updater-go/v3"
"github.com/palantir/stacktrace"
wErrors "github.com/pkg/errors"
log "github.com/sirupsen/logrus"
"github.com/spf13/cobra"
)
Expand Down Expand Up @@ -76,14 +75,14 @@ func RunUpdate(ctx context.Context, opts *UpdateOptions) error {
log.Fatal("Unable to access the Klepto! repository.")
}
if err != nil {
return wErrors.Wrap(err, "failed to retrieve the update release")
return fmt.Errorf("failed to retrieve the update release: %w", err)
}

if updateTo.Name != version {
// Fetch the release and update
if !opts.dryRun {
if err := updater.SelfUpdate(ctx, updateTo); err != nil {
return wErrors.Wrapf(err, "failed to update to version %s", updateTo.Name)
return fmt.Errorf("failed to update to version %s: %w", updateTo.Name, err)
}
}

Expand Down
1 change: 0 additions & 1 deletion go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,6 @@ require (
github.com/icrowley/fake v0.0.0-20180203215853-4178557ae428
github.com/lib/pq v1.10.3
github.com/palantir/stacktrace v0.0.0-20161112013806-78658fd2d177
github.com/pkg/errors v0.9.1
github.com/sirupsen/logrus v1.8.1
github.com/spf13/cobra v1.2.1
github.com/spf13/viper v1.9.0
Expand Down
2 changes: 0 additions & 2 deletions go.sum
Original file line number Diff line number Diff line change
Expand Up @@ -267,8 +267,6 @@ github.com/pelletier/go-toml v1.9.3/go.mod h1:u1nR/EPcESfeI/szUZKdtJ0xRNbUoANCko
github.com/pelletier/go-toml v1.9.4 h1:tjENF6MfZAg8e4ZmZTeWaWiT2vXtsoO6+iuOjFhECwM=
github.com/pelletier/go-toml v1.9.4/go.mod h1:u1nR/EPcESfeI/szUZKdtJ0xRNbUoANCkoOuaOx1Y+c=
github.com/pkg/errors v0.8.1/go.mod h1:bwawxfHBFNV+L2hUp1rHADufV3IMtnDRdf1r5NINEl0=
github.com/pkg/errors v0.9.1 h1:FEBLx1zS214owpjy7qsBeixbURkuhQAwrK5UwLGTwt4=
github.com/pkg/errors v0.9.1/go.mod h1:bwawxfHBFNV+L2hUp1rHADufV3IMtnDRdf1r5NINEl0=
github.com/pkg/sftp v1.10.1/go.mod h1:lYOWFsE0bwd1+KfKJaKeuokY15vzFx25BLbzYYoAxZI=
github.com/pmezard/go-difflib v1.0.0 h1:4DBwDE0NGyQoBHbLQYPwSUPoCMWR5BEzIk/f1lZbAQM=
github.com/pmezard/go-difflib v1.0.0/go.mod h1:iKH77koFhYxTK1pcRnkKkqfTogsbg7gZNVY4sRDYZ/4=
Expand Down
3 changes: 1 addition & 2 deletions pkg/anonymiser/anonymiser.go
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,6 @@ import (
"github.com/hellofresh/klepto/pkg/config"
"github.com/hellofresh/klepto/pkg/database"
"github.com/hellofresh/klepto/pkg/reader"
"github.com/pkg/errors"
log "github.com/sirupsen/logrus"
)

Expand Down Expand Up @@ -109,7 +108,7 @@ func (a *anonymiser) ReadTable(tableName string, rowChan chan<- database.Row, op
}(rowChan, rawChan, table)

if err := a.Reader.ReadTable(tableName, rawChan, opts); err != nil {
return errors.Wrap(err, "anonymiser: error while reading table")
return fmt.Errorf("anonymiser: error while reading table: %w", err)
}

return nil
Expand Down
9 changes: 5 additions & 4 deletions pkg/config/config.go
Original file line number Diff line number Diff line change
@@ -1,11 +1,12 @@
package config

import (
"errors"
"fmt"
"io"
"strings"

"github.com/BurntSushi/toml"
wErrors "github.com/pkg/errors"
log "github.com/sirupsen/logrus"
"github.com/spf13/viper"
)
Expand Down Expand Up @@ -80,21 +81,21 @@ func (t Tables) FindByName(name string) *Table {
// LoadFromFile loads klepto tables config from file
func LoadFromFile(configPath string) (Tables, error) {
if configPath == "" {
return nil, wErrors.New("config file path can not be empty")
return nil, errors.New("config file path can not be empty")
}

log.Debugf("Reading config from %s ...", configPath)
viper.SetConfigFile(configPath)

err := viper.ReadInConfig()
if err != nil {
return nil, wErrors.Wrap(err, "could not read configurations")
return nil, fmt.Errorf("could not read configurations: %w", err)
}

cfgSpec := new(spec)
err = viper.Unmarshal(cfgSpec)
if err != nil {
return nil, wErrors.Wrap(err, "could not unmarshal config file")
return nil, fmt.Errorf("could not unmarshal config file: %w", err)
}

// replace matchers aliases in tables with matchers expressions
Expand Down
3 changes: 1 addition & 2 deletions pkg/dumper/dumper.go
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,6 @@ import (
"fmt"
"time"

wErrors "github.com/pkg/errors"
log "github.com/sirupsen/logrus"

"github.com/hellofresh/klepto/pkg/config"
Expand Down Expand Up @@ -59,7 +58,7 @@ func NewDumper(opts ConnOpts, rdr reader.Reader) (dumper Dumper, err error) {
})

if err != nil {
return nil, wErrors.Wrapf(err, "could not create dumper for DSN: %q", opts.DSN)
return nil, fmt.Errorf("could not create dumper for DSN %q : %w", opts.DSN, err)
}

if dumper == nil {
Expand Down
10 changes: 5 additions & 5 deletions pkg/dumper/engine/engine.go
Original file line number Diff line number Diff line change
@@ -1,9 +1,9 @@
package engine

import (
"fmt"
"sync"

wErrors "github.com/pkg/errors"
log "github.com/sirupsen/logrus"

"github.com/hellofresh/klepto/pkg/config"
Expand Down Expand Up @@ -59,11 +59,11 @@ func (e *Engine) readAndDumpStructure() error {
log.Debug("dumping structure...")
sql, err := e.reader.GetStructure()
if err != nil {
return wErrors.Wrap(err, "failed to get structure")
return fmt.Errorf("failed to get structure: %w", err)
}

if err := e.DumpStructure(sql); err != nil {
return wErrors.Wrap(err, "failed to dump structure")
return fmt.Errorf("failed to dump structure: %w", err)
}

log.Debug("structure was dumped")
Expand All @@ -73,13 +73,13 @@ func (e *Engine) readAndDumpStructure() error {
func (e *Engine) readAndDumpTables(done chan<- struct{}, cfgTables config.Tables, concurrency int) error {
tables, err := e.reader.GetTables()
if err != nil {
return wErrors.Wrap(err, "failed to read and dump tables")
return fmt.Errorf("failed to read and dump tables: %w", err)
}

// Trigger pre dump tables
if adv, ok := e.Dumper.(Hooker); ok {
if err := adv.PreDumpTables(tables); err != nil {
return wErrors.Wrap(err, "failed to execute pre dump tables")
return fmt.Errorf("failed to execute pre dump tables: %w", err)
}
}

Expand Down
19 changes: 9 additions & 10 deletions pkg/dumper/mysql/dumper.go
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,6 @@ import (
"github.com/hellofresh/klepto/pkg/dumper"
"github.com/hellofresh/klepto/pkg/dumper/engine"
"github.com/hellofresh/klepto/pkg/reader"
"github.com/pkg/errors"
log "github.com/sirupsen/logrus"
)

Expand Down Expand Up @@ -73,7 +72,7 @@ func (d *myDumper) DumpTable(tableName string, rowChan <-chan database.Row) erro

txn, err := d.conn.Begin()
if err != nil {
return errors.Wrap(err, "failed to open transaction")
return fmt.Errorf("failed to open transaction: %w", err)
}

insertedRows, err := d.insertIntoTable(txn, tableName, rowChan)
Expand All @@ -83,7 +82,7 @@ func (d *myDumper) DumpTable(tableName string, rowChan <-chan database.Row) erro
log.WithError(err).Error("failed to rollback")
}
}()
err = errors.Wrap(err, "failed to insert rows")
err = fmt.Errorf("failed to insert rows: %w", err)
return err
}

Expand All @@ -93,7 +92,7 @@ func (d *myDumper) DumpTable(tableName string, rowChan <-chan database.Row) erro
}).Debug("inserted rows")

if err := txn.Commit(); err != nil {
return errors.Wrap(err, "failed to commit transaction")
return fmt.Errorf("failed to commit transaction: %w", err)
}

return nil
Expand All @@ -109,14 +108,14 @@ func (d *myDumper) Close() error {
err := d.conn.Close()
if err != nil {
if errGlobalInline != nil {
return errors.Wrap(errGlobalInline, "failed to close mysql connection and `SET GLOBAL local_infile=0`")
return fmt.Errorf("failed to close mysql connection and `SET GLOBAL local_infile=0`: %w", errGlobalInline)
}

return errors.Wrap(err, "failed to close mysql connection")
return fmt.Errorf("failed to close mysql connection: %w", err)
}

if errGlobalInline != nil {
return errors.Wrap(errGlobalInline, "failed `SET GLOBAL local_infile=0` please do this manually!")
return fmt.Errorf("failed `SET GLOBAL local_infile=0` please do this manually! : %w", errGlobalInline)
}

return nil
Expand All @@ -125,7 +124,7 @@ func (d *myDumper) Close() error {
func (d *myDumper) insertIntoTable(txn *sql.Tx, tableName string, rowChan <-chan database.Row) (int64, error) {
columns, err := d.reader.GetColumns(tableName)
if err != nil {
return 0, errors.Wrap(err, "failed to get columns")
return 0, fmt.Errorf("failed to get columns: %w", err)
}

columnsQuoted := make([]string, len(columns))
Expand Down Expand Up @@ -184,11 +183,11 @@ func (d *myDumper) insertIntoTable(txn *sql.Tx, tableName string, rowChan <-chan
defer mysql.DeregisterReaderHandler(tableName)

if _, err := txn.Exec("SET foreign_key_checks = 0;"); err != nil {
return 0, errors.Wrap(err, "failed to disable foreign key checks")
return 0, fmt.Errorf("failed to disable foreign key checks: %w", err)
}

if _, err := txn.Exec(query); err != nil {
return 0, errors.Wrap(err, "failed to execute query")
return 0, fmt.Errorf("failed to execute query: %w", err)
}

return inserted, nil
Expand Down
6 changes: 3 additions & 3 deletions pkg/dumper/mysql/mysql.go
Original file line number Diff line number Diff line change
Expand Up @@ -2,11 +2,11 @@ package mysql

import (
"database/sql"
"fmt"

"github.com/go-sql-driver/mysql"
"github.com/hellofresh/klepto/pkg/dumper"
"github.com/hellofresh/klepto/pkg/reader"
"github.com/pkg/errors"
log "github.com/sirupsen/logrus"
)

Expand All @@ -26,7 +26,7 @@ func (m *driver) IsSupported(dsn string) bool {
func (m *driver) NewConnection(opts dumper.ConnOpts, rdr reader.Reader) (dumper.Dumper, error) {
dsnCfg, err := mysql.ParseDSN(opts.DSN)
if err != nil {
return nil, errors.Wrap(err, "failed to parse mysql dsn")
return nil, fmt.Errorf("failed to parse mysql dsn: %w", err)
}

if !dsnCfg.MultiStatements {
Expand All @@ -37,7 +37,7 @@ func (m *driver) NewConnection(opts dumper.ConnOpts, rdr reader.Reader) (dumper.

conn, err := sql.Open("mysql", dsnCfg.FormatDSN())
if err != nil {
return nil, errors.Wrap(err, "failed to open mysql connection")
return nil, fmt.Errorf("failed to open mysql connection: %w", err)
}

conn.SetMaxOpenConns(opts.MaxConns)
Expand Down
Loading

0 comments on commit 0305d85

Please sign in to comment.