Skip to content

Commit

Permalink
[feature] fix error msg
Browse files Browse the repository at this point in the history
  • Loading branch information
kozmod committed Oct 28, 2023
1 parent d93a1d7 commit 19db59c
Show file tree
Hide file tree
Showing 2 changed files with 4 additions and 5 deletions.
8 changes: 4 additions & 4 deletions transactor.go
Original file line number Diff line number Diff line change
Expand Up @@ -67,25 +67,25 @@ func (t *Transactor[B, C, O]) WithinTx(ctx context.Context, fn func(ctx context.
func (t *Transactor[B, C, O]) WithinTxWithOpts(ctx context.Context, fn func(ctx context.Context) error, opts ...Option[O]) (err error) {
var nilDB B
if t.beginner == nilDB {
return xerrors.Errorf("transactor: cannot begin: %w", ErrNilBeginner)
return xerrors.Errorf("transactor - cannot begin: %w", ErrNilBeginner)
}

tx, ok := t.operator.Extract(ctx)
if !ok {
tx, err = t.beginner.BeginTx(ctx, opts...)
if err != nil {
return xerrors.Errorf("transactor: cannot begin: %w", errors.Join(err, ErrBeginTx))
return xerrors.Errorf("transactor - cannot begin: %w", errors.Join(err, ErrBeginTx))
}
}

defer func() {
switch p := recover(); {
case p != nil:
if rbErr := tx.Rollback(ctx); rbErr != nil {
err = xerrors.Errorf("transactor: panic: %v: %w", p, errors.Join(rbErr, ErrRollbackFailed))
err = xerrors.Errorf("transactor - panic [%v]: %w", p, errors.Join(rbErr, ErrRollbackFailed))
return
}
err = xerrors.Errorf("transactor: panic: %v: %w", p, ErrRollbackSuccess)
err = xerrors.Errorf("transactor - panic [%v]: %w", p, ErrRollbackSuccess)
case err != nil:
if rbErr := tx.Rollback(ctx); rbErr != nil {
err = xerrors.Errorf("transactor: %w", errors.Join(err, rbErr, ErrRollbackFailed))
Expand Down
1 change: 0 additions & 1 deletion transactor_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -231,7 +231,6 @@ func Test_Transactor(t *testing.T) {
assertTrue(t, &c == tx)
return execError
})
t.Log(err.Error())
assertTrue(t, errors.Is(err, ErrRollbackFailed))
assertTrue(t, errors.Is(err, execError))
assertTrue(t, errors.Is(err, rollbackErr))
Expand Down

0 comments on commit 19db59c

Please sign in to comment.