Skip to content

Commit

Permalink
Fix doc discrepancies between Tx interface and pgxpool implementation
Browse files Browse the repository at this point in the history
The error is not wrapped at the moment, but document that it may be.

fixes #2104
  • Loading branch information
jackc committed Aug 7, 2024
1 parent a68e14f commit c457de6
Showing 1 changed file with 7 additions and 6 deletions.
13 changes: 7 additions & 6 deletions pgxpool/tx.go
Original file line number Diff line number Diff line change
Expand Up @@ -18,9 +18,10 @@ func (tx *Tx) Begin(ctx context.Context) (pgx.Tx, error) {
return tx.t.Begin(ctx)
}

// Commit commits the transaction and returns the associated connection back to the Pool. Commit will return ErrTxClosed
// if the Tx is already closed, but is otherwise safe to call multiple times. If the commit fails with a rollback status
// (e.g. the transaction was already in a broken state) then ErrTxCommitRollback will be returned.
// Commit commits the transaction and returns the associated connection back to the Pool. Commit will return an error
// where errors.Is(ErrTxClosed) is true if the Tx is already closed, but is otherwise safe to call multiple times. If
// the commit fails with a rollback status (e.g. the transaction was already in a broken state) then ErrTxCommitRollback
// will be returned.
func (tx *Tx) Commit(ctx context.Context) error {
err := tx.t.Commit(ctx)
if tx.c != nil {
Expand All @@ -30,9 +31,9 @@ func (tx *Tx) Commit(ctx context.Context) error {
return err
}

// Rollback rolls back the transaction and returns the associated connection back to the Pool. Rollback will return ErrTxClosed
// if the Tx is already closed, but is otherwise safe to call multiple times. Hence, defer tx.Rollback() is safe even if
// tx.Commit() will be called first in a non-error condition.
// Rollback rolls back the transaction and returns the associated connection back to the Pool. Rollback will return
// where an error where errors.Is(ErrTxClosed) is true if the Tx is already closed, but is otherwise safe to call
// multiple times. Hence, defer tx.Rollback() is safe even if tx.Commit() will be called first in a non-error condition.
func (tx *Tx) Rollback(ctx context.Context) error {
err := tx.t.Rollback(ctx)
if tx.c != nil {
Expand Down

0 comments on commit c457de6

Please sign in to comment.