chore: wrap errors to custom errors

This commit is contained in:
adlerhurst
2025-07-17 00:54:21 +02:00
parent 75a04e83ae
commit f8934b0c88
10 changed files with 331 additions and 69 deletions

View File

@@ -25,7 +25,7 @@ func (c *pgxConn) Release(_ context.Context) error {
func (c *pgxConn) Begin(ctx context.Context, opts *database.TransactionOptions) (database.Transaction, error) {
tx, err := c.Conn.BeginTx(ctx, transactionOptionsToPgx(opts))
if err != nil {
return nil, err
return nil, wrapError(err)
}
return &pgxTx{tx}, nil
}
@@ -34,7 +34,10 @@ func (c *pgxConn) Begin(ctx context.Context, opts *database.TransactionOptions)
// Subtle: this method shadows the method (*Conn).Query of pgxConn.Conn.
func (c *pgxConn) Query(ctx context.Context, sql string, args ...any) (database.Rows, error) {
rows, err := c.Conn.Query(ctx, sql, args...)
return &Rows{rows}, err
if err != nil {
return nil, wrapError(err)
}
return &Rows{rows}, nil
}
// QueryRow implements sql.Client.
@@ -47,7 +50,10 @@ func (c *pgxConn) QueryRow(ctx context.Context, sql string, args ...any) databas
// Subtle: this method shadows the method (Pool).Exec of pgxPool.Pool.
func (c *pgxConn) Exec(ctx context.Context, sql string, args ...any) (int64, error) {
res, err := c.Conn.Exec(ctx, sql, args...)
return res.RowsAffected(), err
if err != nil {
return 0, wrapError(err)
}
return res.RowsAffected(), nil
}
// Migrate implements [database.Migrator].
@@ -57,5 +63,5 @@ func (c *pgxConn) Migrate(ctx context.Context) error {
}
err := migration.Migrate(ctx, c.Conn.Conn())
isMigrated = err == nil
return err
return wrapError(err)
}