Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

removes errors.WithStack as its noisy and makes it harder to understand #372

Merged
merged 2 commits into from
Apr 4, 2019
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 1 addition & 2 deletions callbacks.go
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,6 @@ package pop
import (
"reflect"

"github.com/pkg/errors"
"golang.org/x/sync/errgroup"
)

Expand All @@ -16,7 +15,7 @@ type AfterFindable interface {
func (m *Model) afterFind(c *Connection) error {
if x, ok := m.Value.(AfterFindable); ok {
if err := x.AfterFind(c); err != nil {
return errors.WithStack(err)
return err
}
}

Expand Down
6 changes: 3 additions & 3 deletions config.go
Original file line number Diff line number Diff line change
Expand Up @@ -40,13 +40,13 @@ func init() {
func LoadConfigFile() error {
path, err := findConfigPath()
if err != nil {
return errors.WithStack(err)
return err
}
Connections = map[string]*Connection{}
log(logging.Debug, "Loading config file from %s", path)
f, err := os.Open(path)
if err != nil {
return errors.WithStack(err)
return err
}
return LoadFrom(f)
}
Expand Down Expand Up @@ -104,7 +104,7 @@ func ParseConfig(r io.Reader) (map[string]*ConnectionDetails, error) {
})
b, err := ioutil.ReadAll(r)
if err != nil {
return nil, errors.WithStack(err)
return nil, err
}
t, err := tmpl.Parse(string(b))
if err != nil {
Expand Down
8 changes: 4 additions & 4 deletions connection.go
Original file line number Diff line number Diff line change
Expand Up @@ -48,7 +48,7 @@ func (c *Connection) MigrationTableName() string {
func NewConnection(deets *ConnectionDetails) (*Connection, error) {
err := deets.Finalize()
if err != nil {
return nil, errors.WithStack(err)
return nil, err
}
c := &Connection{
ID: randx.String(30),
Expand All @@ -73,7 +73,7 @@ func Connect(e string) (*Connection, error) {
if len(Connections) == 0 {
err := LoadConfigFile()
if err != nil {
return nil, errors.WithStack(err)
return nil, err
}
}
e = defaults.String(e, "development")
Expand Down Expand Up @@ -133,7 +133,7 @@ func (c *Connection) Transaction(fn func(tx *Connection) error) error {
dberr = cn.TX.Commit()
}
if err != nil {
return errors.WithStack(err)
return err
}
return errors.Wrap(dberr, "error committing or rolling back transaction")
})
Expand Down Expand Up @@ -201,7 +201,7 @@ func (c *Connection) timeFunc(name string, fn func() error) error {
err := fn()
atomic.AddInt64(&c.Elapsed, int64(time.Since(start)))
if err != nil {
return errors.WithStack(err)
return err
}
return nil
}
6 changes: 3 additions & 3 deletions dialect_cockroach.go
Original file line number Diff line number Diff line change
Expand Up @@ -76,14 +76,14 @@ func (p *cockroach) Create(s store, model *Model, cols columns.Columns) error {
log(logging.SQL, query)
stmt, err := s.PrepareNamed(query)
if err != nil {
return errors.WithStack(err)
return err
}
err = stmt.Get(&id, model.Value)
if err != nil {
if err := stmt.Close(); err != nil {
return errors.WithMessage(err, "failed to close statement")
}
return errors.WithStack(err)
return err
}
model.setID(id.ID)
return errors.WithMessage(stmt.Close(), "failed to close statement")
Expand All @@ -98,7 +98,7 @@ func (p *cockroach) Update(s store, model *Model, cols columns.Columns) error {
func (p *cockroach) Destroy(s store, model *Model) error {
stmt := p.TranslateSQL(fmt.Sprintf("DELETE FROM %s WHERE %s", model.TableName(), model.whereID()))
_, err := genericExec(s, stmt, model.ID())
return errors.WithStack(err)
return err
}

func (p *cockroach) SelectOne(s store, model *Model, query Query) error {
Expand Down
20 changes: 10 additions & 10 deletions dialect_common.go
Original file line number Diff line number Diff line change
Expand Up @@ -44,22 +44,22 @@ func genericCreate(s store, model *Model, cols columns.Columns) error {
log(logging.SQL, query)
res, err := s.NamedExec(query, model.Value)
if err != nil {
return errors.WithStack(err)
return err
}
id, err = res.LastInsertId()
if err == nil {
model.setID(id)
}
if err != nil {
return errors.WithStack(err)
return err
}
return nil
case "UUID", "string":
if keyType == "UUID" {
if model.ID() == emptyUUID {
u, err := uuid.NewV4()
if err != nil {
return errors.WithStack(err)
return err
}
model.setID(u)
}
Expand All @@ -72,14 +72,14 @@ func genericCreate(s store, model *Model, cols columns.Columns) error {
log(logging.SQL, query)
stmt, err := s.PrepareNamed(query)
if err != nil {
return errors.WithStack(err)
return err
}
_, err = stmt.Exec(model.Value)
if err != nil {
if err := stmt.Close(); err != nil {
return errors.WithMessage(err, "failed to close statement")
}
return errors.WithStack(err)
return err
}
return errors.WithMessage(stmt.Close(), "failed to close statement")
}
Expand All @@ -91,7 +91,7 @@ func genericUpdate(s store, model *Model, cols columns.Columns) error {
log(logging.SQL, stmt, model.ID())
_, err := s.NamedExec(stmt, model.Value)
if err != nil {
return errors.WithStack(err)
return err
}
return nil
}
Expand All @@ -100,23 +100,23 @@ func genericDestroy(s store, model *Model) error {
stmt := fmt.Sprintf("DELETE FROM %s WHERE %s", model.TableName(), model.whereID())
_, err := genericExec(s, stmt, model.ID())
if err != nil {
return errors.WithStack(err)
return err
}
return nil
}

func genericExec(s store, stmt string, args ...interface{}) (sql.Result, error) {
log(logging.SQL, stmt, args...)
res, err := s.Exec(stmt, args...)
return res, errors.WithStack(err)
return res, err
}

func genericSelectOne(s store, model *Model, query Query) error {
sql, args := query.ToSQL(model)
log(logging.SQL, sql, args...)
err := s.Get(model.Value, sql, args...)
if err != nil {
return errors.WithStack(err)
return err
}
return nil
}
Expand All @@ -126,7 +126,7 @@ func genericSelectMany(s store, models *Model, query Query) error {
log(logging.SQL, sql, args...)
err := s.Select(models.Value, sql, args...)
if err != nil {
return errors.WithStack(err)
return err
}
return nil
}
Expand Down
6 changes: 3 additions & 3 deletions dialect_postgresql.go
Original file line number Diff line number Diff line change
Expand Up @@ -65,14 +65,14 @@ func (p *postgresql) Create(s store, model *Model, cols columns.Columns) error {
log(logging.SQL, query)
stmt, err := s.PrepareNamed(query)
if err != nil {
return errors.WithStack(err)
return err
}
err = stmt.Get(&id, model.Value)
if err != nil {
if err := stmt.Close(); err != nil {
return errors.WithMessage(err, "failed to close statement")
}
return errors.WithStack(err)
return err
}
model.setID(id.ID)
return errors.WithMessage(stmt.Close(), "failed to close statement")
Expand All @@ -88,7 +88,7 @@ func (p *postgresql) Destroy(s store, model *Model) error {
stmt := p.TranslateSQL(fmt.Sprintf("DELETE FROM %s WHERE %s", model.TableName(), model.whereID()))
_, err := genericExec(s, stmt, model.ID())
if err != nil {
return errors.WithStack(err)
return err
}
return nil
}
Expand Down
4 changes: 2 additions & 2 deletions dialect_sqlite.go
Original file line number Diff line number Diff line change
Expand Up @@ -70,14 +70,14 @@ func (m *sqlite) Create(s store, model *Model, cols columns.Columns) error {
log(logging.SQL, query)
res, err := s.NamedExec(query, model.Value)
if err != nil {
return errors.WithStack(err)
return err
}
id, err = res.LastInsertId()
if err == nil {
model.setID(id)
}
if err != nil {
return errors.WithStack(err)
return err
}
return nil
}
Expand Down
4 changes: 2 additions & 2 deletions file_migrator.go
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,7 @@ func NewFileMigrator(path string, c *Connection) (FileMigrator, error) {

err := fm.findMigrations()
if err != nil {
return fm, errors.WithStack(err)
return fm, err
}

return fm, nil
Expand Down Expand Up @@ -68,7 +68,7 @@ func (fm *FileMigrator) findMigrations() error {
Runner: func(mf Migration, tx *Connection) error {
f, err := os.Open(p)
if err != nil {
return errors.WithStack(err)
return err
}
content, err := migrationContent(mf, tx, f)
if err != nil {
Expand Down
2 changes: 1 addition & 1 deletion genny/config/config-packr.go

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

6 changes: 3 additions & 3 deletions genny/config/config.go
Original file line number Diff line number Diff line change
@@ -1,12 +1,12 @@
package config

import (
"fmt"
"path/filepath"

"github.com/gobuffalo/genny"
"github.com/gobuffalo/gogen"
"github.com/gobuffalo/packr/v2"
"github.com/pkg/errors"
)

var templates = packr.New("pop:genny:config", "../config/templates")
Expand All @@ -15,12 +15,12 @@ var templates = packr.New("pop:genny:config", "../config/templates")
func New(opts *Options) (*genny.Generator, error) {
g := genny.New()
if err := opts.Validate(); err != nil {
return g, errors.WithStack(err)
return g, err
}

f, err := templates.Open(opts.Dialect + ".yml.tmpl")
if err != nil {
return g, errors.Errorf("unable to find database.yml template for dialect %s", opts.Dialect)
return g, fmt.Errorf("unable to find database.yml template for dialect %s", opts.Dialect)
}

name := filepath.Join(opts.Root, opts.FileName+".tmpl")
Expand Down
2 changes: 1 addition & 1 deletion genny/config/options.go
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ package config
import (
"os"

"github.com/pkg/errors"
"errors"
)

// Options needed for the config generator
Expand Down
9 changes: 4 additions & 5 deletions migration.go
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,6 @@ import (

"github.com/gobuffalo/makr"
"github.com/markbates/oncer"
"github.com/pkg/errors"
)

// MigrationCreate writes contents for a given migration in normalized files
Expand All @@ -31,7 +30,7 @@ func (c *Connection) MigrateUp(path string) error {

mig, err := NewFileMigrator(path, c)
if err != nil {
return errors.WithStack(err)
return err
}
return mig.Up()
}
Expand All @@ -42,7 +41,7 @@ func (c *Connection) MigrateDown(path string, step int) error {

mig, err := NewFileMigrator(path, c)
if err != nil {
return errors.WithStack(err)
return err
}
return mig.Down(step)
}
Expand All @@ -53,7 +52,7 @@ func (c *Connection) MigrateStatus(path string) error {

mig, err := NewFileMigrator(path, c)
if err != nil {
return errors.WithStack(err)
return err
}
return mig.Status()
}
Expand All @@ -64,7 +63,7 @@ func (c *Connection) MigrateReset(path string) error {

mig, err := NewFileMigrator(path, c)
if err != nil {
return errors.WithStack(err)
return err
}
return mig.Reset()
}
4 changes: 2 additions & 2 deletions migration_box.go
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@ func NewMigrationBox(box packd.Walkable, c *Connection) (MigrationBox, error) {

err := fm.findMigrations()
if err != nil {
return fm, errors.WithStack(err)
return fm, err
}

return fm, nil
Expand All @@ -34,7 +34,7 @@ func (fm *MigrationBox) findMigrations() error {
return fm.Box.Walk(func(p string, f packd.File) error {
info, err := f.FileInfo()
if err != nil {
return errors.WithStack(err)
return err
}
matches := mrx.FindAllStringSubmatch(info.Name(), -1)
if len(matches) == 0 {
Expand Down
4 changes: 2 additions & 2 deletions migration_info.go
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
package pop

import "github.com/pkg/errors"
import "fmt"

// Migration handles the data for a given database migration
type Migration struct {
Expand All @@ -24,7 +24,7 @@ type Migration struct {
// no mf.Runner defined.
func (mf Migration) Run(c *Connection) error {
if mf.Runner == nil {
return errors.Errorf("no runner defined for %s", mf.Path)
return fmt.Errorf("no runner defined for %s", mf.Path)
}
return mf.Runner(mf, c)
}
Expand Down
Loading