Skip to content

Commit

Permalink
Wrap errors for better debugability
Browse files Browse the repository at this point in the history
  • Loading branch information
cristaloleg committed Jun 27, 2023
1 parent 924fc68 commit ff60fff
Showing 1 changed file with 4 additions and 4 deletions.
8 changes: 4 additions & 4 deletions dbump.go
Original file line number Diff line number Diff line change
Expand Up @@ -191,7 +191,7 @@ func (m *mig) load() ([]*Migration, error) {

func (m *mig) runMigrations(ctx context.Context, ms []*Migration) (err error) {
if err := m.lockDB(ctx); err != nil {
return err
return fmt.Errorf("lock db: %w", err)
}

defer func() {
Expand Down Expand Up @@ -241,14 +241,14 @@ func (m *mig) unlockDB(ctx context.Context) error {
func (m *mig) runMigrationsLocked(ctx context.Context, ms []*Migration) error {
curr, target, err := m.getCurrAndTargetVersions(ctx, len(ms))
if err != nil {
return err
return fmt.Errorf("version get: %w", err)
}

for _, step := range m.prepareSteps(curr, target, ms) {
for i, step := range m.prepareSteps(curr, target, ms) {
m.BeforeStep(ctx, step)

if err := m.step(ctx, step); err != nil {
return err
return fmt.Errorf("migration %d: %w", i, err)
}

m.AfterStep(ctx, step)
Expand Down

0 comments on commit ff60fff

Please sign in to comment.