Fix doc discrepancies between Tx interface and pgxpool implementation

The error is not wrapped at the moment, but document that it may be.

fixes https://github.com/jackc/pgx/issues/2104
pull/2108/head
Jack Christensen 2024-08-07 08:02:15 -05:00
parent a68e14fe5a
commit c457de62c9
1 changed files with 7 additions and 6 deletions

View File

@ -18,9 +18,10 @@ func (tx *Tx) Begin(ctx context.Context) (pgx.Tx, error) {
return tx.t.Begin(ctx) return tx.t.Begin(ctx)
} }
// Commit commits the transaction and returns the associated connection back to the Pool. Commit will return ErrTxClosed // Commit commits the transaction and returns the associated connection back to the Pool. Commit will return an error
// if the Tx is already closed, but is otherwise safe to call multiple times. If the commit fails with a rollback status // where errors.Is(ErrTxClosed) is true if the Tx is already closed, but is otherwise safe to call multiple times. If
// (e.g. the transaction was already in a broken state) then ErrTxCommitRollback will be returned. // 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 { func (tx *Tx) Commit(ctx context.Context) error {
err := tx.t.Commit(ctx) err := tx.t.Commit(ctx)
if tx.c != nil { if tx.c != nil {
@ -30,9 +31,9 @@ func (tx *Tx) Commit(ctx context.Context) error {
return err return err
} }
// Rollback rolls back the transaction and returns the associated connection back to the Pool. Rollback will return ErrTxClosed // Rollback rolls back the transaction and returns the associated connection back to the Pool. Rollback will return
// if the Tx is already closed, but is otherwise safe to call multiple times. Hence, defer tx.Rollback() is safe even if // where an error where errors.Is(ErrTxClosed) is true if the Tx is already closed, but is otherwise safe to call
// tx.Commit() will be called first in a non-error condition. // 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 { func (tx *Tx) Rollback(ctx context.Context) error {
err := tx.t.Rollback(ctx) err := tx.t.Rollback(ctx)
if tx.c != nil { if tx.c != nil {