fix: add error logging to remaining nolint:errcheck scan sites for observability
CI / Env docs check (push) Successful in 15s
CI / Docker compose check (push) Successful in 16s
CI / Nginx config check (push) Successful in 20s
CI / Frontend major deps (push) Successful in 30s
CI / Frontend deps check (push) Successful in 32s
CI / Secrets scan (push) Successful in 47s
CI / Go build (push) Successful in 44s
CI / Frontend build (push) Successful in 49s
CI / Go vet (dev) (push) Has been cancelled
CI / Go vet (prod) (push) Has been cancelled
CI / golangci-lint (push) Has been cancelled
CI / Staticcheck (dev) (push) Has been cancelled
CI / Staticcheck (prod) (push) Has been cancelled
CI / Security scan (dev) (push) Has been cancelled
CI / Security scan (prod) (push) Has been cancelled
CI / go mod tidy (push) Has been cancelled
CI / Tests (prod) (push) Has been cancelled
CI / Tests (dev) (push) Has been cancelled
CI / Race (prod) (push) Has been cancelled
CI / Race (dev) (push) Has been cancelled
CI / Go vulnerabilities (push) Has been cancelled
CI / Knip (push) Has been cancelled
CI / Frontend a11y check (push) Has been cancelled
CI / Svelte strict check (push) Has been cancelled
CI / Frontend QC (audit) (push) Has been cancelled
CI / Frontend QC (typecheck) (push) Has been cancelled
CI / Frontend QC (lint) (push) Has been cancelled

This commit is contained in:
2026-07-11 15:04:53 +01:00
parent ad15127777
commit f147be0b99
7 changed files with 90 additions and 61 deletions
+13 -9
View File
@@ -207,11 +207,13 @@ func GetGiftCards(w http.ResponseWriter, r *http.Request) {
if searchTerm != "" {
countArgs = append(countArgs, "%"+searchTerm+"%")
}
//nolint:errcheck // zero value is acceptable fallback on scan failure
_ = db.Conn.QueryRow(ctx, "SELECT COUNT(*) FROM gift_cards "+whereSQL, countArgs...).Scan(&gcTotal)
if err := db.Conn.QueryRow(ctx, "SELECT COUNT(*) FROM gift_cards "+whereSQL, countArgs...).Scan(&gcTotal); err != nil {
log.Printf("Failed to scan filtered gift card count: %v", err)
}
} else {
//nolint:errcheck // zero value is acceptable fallback on scan failure
_ = db.Conn.QueryRow(ctx, "SELECT COUNT(*) FROM gift_cards").Scan(&gcTotal)
if err := db.Conn.QueryRow(ctx, "SELECT COUNT(*) FROM gift_cards").Scan(&gcTotal); err != nil {
log.Printf("Failed to scan gift card count: %v", err)
}
}
gcRows, err := db.Conn.Query(ctx, gcListQuery, gcListArgs...)
@@ -283,13 +285,15 @@ func GetGiftCards(w http.ResponseWriter, r *http.Request) {
// Count query for user balances.
if searchTerm != "" {
//nolint:errcheck // zero value is acceptable fallback on scan failure
_ = db.Conn.QueryRow(ctx, `SELECT COUNT(*) FROM user_giftcard_balances b
if err := db.Conn.QueryRow(ctx, `SELECT COUNT(*) FROM user_giftcard_balances b
JOIN users u ON b.user_id = u.id
WHERE u.n_first_name ILIKE $1 OR u.n_last_name ILIKE $1 OR u.email ILIKE $1`, "%"+searchTerm+"%").Scan(&ubTotal)
WHERE u.n_first_name ILIKE $1 OR u.n_last_name ILIKE $1 OR u.email ILIKE $1`, "%"+searchTerm+"%").Scan(&ubTotal); err != nil {
log.Printf("Failed to scan filtered user balance count: %v", err)
}
} else {
//nolint:errcheck // zero value is acceptable fallback on scan failure
_ = db.Conn.QueryRow(ctx, "SELECT COUNT(*) FROM user_giftcard_balances").Scan(&ubTotal)
if err := db.Conn.QueryRow(ctx, "SELECT COUNT(*) FROM user_giftcard_balances").Scan(&ubTotal); err != nil {
log.Printf("Failed to scan user balance count: %v", err)
}
}
for ubRows.Next() {
+48 -33
View File
@@ -165,8 +165,9 @@ func calculateDiscountPreview(ctx context.Context, bookingID string, userID stri
ORDER BY discount_percent DESC LIMIT 1
`).Scan(&campaignID, &campaignPercent, &campaignName); err == nil && campaignID != "" {
var exists int
//nolint:errcheck // zero value is acceptable fallback on scan failure
_ = db.Conn.QueryRow(ctx, `SELECT 1 FROM booking_discounts WHERE booking_id = $1 AND source_id = $2`, bookingID, campaignID).Scan(&exists)
if err := db.Conn.QueryRow(ctx, `SELECT 1 FROM booking_discounts WHERE booking_id = $1 AND source_id = $2`, bookingID, campaignID).Scan(&exists); err != nil {
log.Printf("Failed to scan campaign discount existence: %v", err)
}
if exists == 0 {
amount := roundTo2(bookingTotal * campaignPercent / 100)
resp.Discounts = append(resp.Discounts, DiscountPreview{
@@ -180,8 +181,9 @@ func calculateDiscountPreview(ctx context.Context, bookingID string, userID stri
}
var userBookingCount int
//nolint:errcheck // zero value is acceptable fallback on scan failure
_ = db.Conn.QueryRow(ctx, `SELECT COUNT(*) FROM bookings WHERE user_id = $1 AND status = 'completed'`, userID).Scan(&userBookingCount)
if err := db.Conn.QueryRow(ctx, `SELECT COUNT(*) FROM bookings WHERE user_id = $1 AND status = 'completed'`, userID).Scan(&userBookingCount); err != nil {
log.Printf("Failed to scan user completed booking count: %v", err)
}
var milestoneCampaignID string
var milestonePercent float64
@@ -197,8 +199,9 @@ func calculateDiscountPreview(ctx context.Context, bookingID string, userID stri
if milestoneCampaignID != "" {
var exists int
//nolint:errcheck // zero value is acceptable fallback on scan failure
_ = db.Conn.QueryRow(ctx, `SELECT 1 FROM booking_discounts WHERE booking_id = $1 AND source_id = $2`, bookingID, milestoneCampaignID).Scan(&exists)
if err := db.Conn.QueryRow(ctx, `SELECT 1 FROM booking_discounts WHERE booking_id = $1 AND source_id = $2`, bookingID, milestoneCampaignID).Scan(&exists); err != nil {
log.Printf("Failed to scan milestone discount existence: %v", err)
}
if exists == 0 {
amount := roundTo2(bookingTotal * milestonePercent / 100)
resp.Discounts = append(resp.Discounts, DiscountPreview{
@@ -212,8 +215,9 @@ func calculateDiscountPreview(ctx context.Context, bookingID string, userID stri
}
var firstVisitDate time.Time
//nolint:errcheck // zero value is acceptable fallback on scan failure
_ = db.Conn.QueryRow(ctx, `SELECT MIN(start_time) FROM bookings WHERE user_id = $1 AND status = 'completed'`, userID).Scan(&firstVisitDate)
if err := db.Conn.QueryRow(ctx, `SELECT MIN(start_time) FROM bookings WHERE user_id = $1 AND status = 'completed'`, userID).Scan(&firstVisitDate); err != nil {
log.Printf("Failed to scan first visit date: %v", err)
}
if !firstVisitDate.IsZero() {
type annCamp struct {
id string
@@ -238,9 +242,10 @@ func calculateDiscountPreview(ctx context.Context, bookingID string, userID stri
annRows.Close()
for _, c := range campaigns {
var exists int
//nolint:errcheck // zero value is acceptable fallback on scan failure
_ = db.Conn.QueryRow(ctx, `SELECT 1 FROM booking_discounts WHERE booking_id = $1 AND source_id = $2`, bookingID, c.id).Scan(&exists)
var exists int
if err := db.Conn.QueryRow(ctx, `SELECT 1 FROM booking_discounts WHERE booking_id = $1 AND source_id = $2`, bookingID, c.id).Scan(&exists); err != nil {
log.Printf("Failed to scan anniversary discount existence: %v", err)
}
if exists > 0 {
continue
}
@@ -276,8 +281,9 @@ func calculateDiscountPreview(ctx context.Context, bookingID string, userID stri
LIMIT 1
`, userID).Scan(&rdID, &rdPercent); err == nil && rdID != "" {
exists := 0
//nolint:errcheck // zero value is acceptable fallback on scan failure
_ = db.Conn.QueryRow(ctx, `SELECT 1 FROM booking_discounts WHERE booking_id = $1 AND discount_source = 'referral' AND source_id = $2`, bookingID, rdID).Scan(&exists)
if err := db.Conn.QueryRow(ctx, `SELECT 1 FROM booking_discounts WHERE booking_id = $1 AND discount_source = 'referral' AND source_id = $2`, bookingID, rdID).Scan(&exists); err != nil {
log.Printf("Failed to scan referral discount existence: %v", err)
}
if exists == 0 {
amount := roundTo2(bookingTotal * rdPercent / 100)
resp.Discounts = append(resp.Discounts, DiscountPreview{
@@ -1080,11 +1086,12 @@ func CreateBookingPayment(w http.ResponseWriter, r *http.Request) {
// would create a credit balance or require a refund.
func applyEligibleCampaignsAtPayment(ctx context.Context, q db.Querier, bookingID string, userID string) {
var existingPayment int
//nolint:errcheck // zero value is acceptable fallback on scan failure
_ = q.QueryRow(ctx, `
if err := q.QueryRow(ctx, `
SELECT COUNT(*) FROM payments
WHERE booking_id = $1 AND status = 'completed' AND payment_method NOT IN ('discount', 'on_the_house')
`, bookingID).Scan(&existingPayment)
`, bookingID).Scan(&existingPayment); err != nil {
log.Printf("Failed to scan existing payment count: %v", err)
}
// Only block if this is the 2nd+ real payment — the first payment should still
// trigger discount application (existingPayment counts already-completed payments
// visible within the transaction, including the just-inserted one).
@@ -1113,8 +1120,9 @@ func applyEligibleCampaignsAtPayment(ctx context.Context, q db.Querier, bookingI
ORDER BY discount_percent DESC LIMIT 1
`).Scan(&campaignID, &campaignPercent); err == nil && campaignID != "" {
var exists int
//nolint:errcheck // zero value is acceptable fallback on scan failure
_ = q.QueryRow(ctx, `SELECT 1 FROM booking_discounts WHERE booking_id = $1 AND source_id = $2`, bookingID, campaignID).Scan(&exists)
if err := q.QueryRow(ctx, `SELECT 1 FROM booking_discounts WHERE booking_id = $1 AND source_id = $2`, bookingID, campaignID).Scan(&exists); err != nil {
log.Printf("Failed to scan time-based campaign discount existence: %v", err)
}
if exists == 0 {
discountAmount := roundTo2(bookingTotal * campaignPercent / 100)
if _, err := q.Exec(ctx, `
@@ -1139,8 +1147,9 @@ func applyEligibleCampaignsAtPayment(ctx context.Context, q db.Querier, bookingI
}
var userBookingCount int
//nolint:errcheck // zero value is acceptable fallback on scan failure
_ = q.QueryRow(ctx, `SELECT COUNT(*) FROM bookings WHERE user_id = $1 AND status = 'completed'`, userID).Scan(&userBookingCount)
if err := q.QueryRow(ctx, `SELECT COUNT(*) FROM bookings WHERE user_id = $1 AND status = 'completed'`, userID).Scan(&userBookingCount); err != nil {
log.Printf("Failed to scan user booking count: %v", err)
}
var milestoneCampaignID string
var milestonePercent float64
@@ -1155,8 +1164,9 @@ func applyEligibleCampaignsAtPayment(ctx context.Context, q db.Querier, bookingI
if milestoneCampaignID != "" {
var exists int
//nolint:errcheck // zero value is acceptable fallback on scan failure
_ = q.QueryRow(ctx, `SELECT 1 FROM booking_discounts WHERE booking_id = $1 AND source_id = $2`, bookingID, milestoneCampaignID).Scan(&exists)
if err := q.QueryRow(ctx, `SELECT 1 FROM booking_discounts WHERE booking_id = $1 AND source_id = $2`, bookingID, milestoneCampaignID).Scan(&exists); err != nil {
log.Printf("Failed to scan milestone campaign discount existence: %v", err)
}
if exists == 0 {
discountAmount := roundTo2(bookingTotal * milestonePercent / 100)
if _, err := q.Exec(ctx, `
@@ -1181,8 +1191,9 @@ func applyEligibleCampaignsAtPayment(ctx context.Context, q db.Querier, bookingI
}
var firstVisitDate time.Time
//nolint:errcheck // zero value is acceptable fallback on scan failure
_ = q.QueryRow(ctx, `SELECT MIN(start_time) FROM bookings WHERE user_id = $1 AND status = 'completed'`, userID).Scan(&firstVisitDate)
if err := q.QueryRow(ctx, `SELECT MIN(start_time) FROM bookings WHERE user_id = $1 AND status = 'completed'`, userID).Scan(&firstVisitDate); err != nil {
log.Printf("Failed to scan first visit date: %v", err)
}
if !firstVisitDate.IsZero() {
annRows, err := q.Query(ctx, `
SELECT id, discount_percent, milestone_value, milestone_unit FROM discount_campaigns
@@ -1206,9 +1217,10 @@ func applyEligibleCampaignsAtPayment(ctx context.Context, q db.Querier, bookingI
annRows.Close()
for _, c := range campaigns {
var exists int
//nolint:errcheck // zero value is acceptable fallback on scan failure
_ = q.QueryRow(ctx, `SELECT 1 FROM booking_discounts WHERE booking_id = $1 AND source_id = $2`, bookingID, c.id).Scan(&exists)
var exists int
if err := q.QueryRow(ctx, `SELECT 1 FROM booking_discounts WHERE booking_id = $1 AND source_id = $2`, bookingID, c.id).Scan(&exists); err != nil {
log.Printf("Failed to scan anniversary discount existence: %v", err)
}
if exists > 0 {
continue
}
@@ -1256,8 +1268,9 @@ func applyEligibleCampaignsAtPayment(ctx context.Context, q db.Querier, bookingI
SELECT payment_method FROM payments WHERE booking_id = $1 AND payment_method NOT IN ('discount', 'on_the_house') ORDER BY created_at ASC LIMIT 1
`, bookingID).Scan(&firstPaymentMethod); err == nil && firstPaymentMethod == "in_person_card" {
var globalCount int
//nolint:errcheck // zero value is acceptable fallback on scan failure
_ = q.QueryRow(ctx, `SELECT COUNT(*) FROM bookings WHERE status = 'completed'`).Scan(&globalCount)
if err := q.QueryRow(ctx, `SELECT COUNT(*) FROM bookings WHERE status = 'completed'`).Scan(&globalCount); err != nil {
log.Printf("Failed to scan global completed booking count: %v", err)
}
var globalCampaignID string
var globalPercent float64
@@ -1274,8 +1287,9 @@ func applyEligibleCampaignsAtPayment(ctx context.Context, q db.Querier, bookingI
if globalCampaignID != "" {
var exists int
//nolint:errcheck // zero value is acceptable fallback on scan failure
_ = q.QueryRow(ctx, `SELECT 1 FROM booking_discounts WHERE booking_id = $1 AND source_id = $2`, bookingID, globalCampaignID).Scan(&exists)
if err := q.QueryRow(ctx, `SELECT 1 FROM booking_discounts WHERE booking_id = $1 AND source_id = $2`, bookingID, globalCampaignID).Scan(&exists); err != nil {
log.Printf("Failed to scan global campaign discount existence: %v", err)
}
if exists == 0 {
discountAmount := roundTo2(bookingTotal * globalPercent / 100)
if _, err := q.Exec(ctx, `
@@ -1310,8 +1324,9 @@ func applyEligibleCampaignsAtPayment(ctx context.Context, q db.Querier, bookingI
LIMIT 1
`, userID).Scan(&rdID, &rdPercent); err == nil && rdID != "" {
exists := 0
//nolint:errcheck // zero value is acceptable fallback on scan failure
_ = q.QueryRow(ctx, `SELECT 1 FROM booking_discounts WHERE booking_id = $1 AND discount_source = 'referral' AND source_id = $2`, bookingID, rdID).Scan(&exists)
if err := q.QueryRow(ctx, `SELECT 1 FROM booking_discounts WHERE booking_id = $1 AND discount_source = 'referral' AND source_id = $2`, bookingID, rdID).Scan(&exists); err != nil {
log.Printf("Failed to scan referral discount existence: %v", err)
}
if exists == 0 {
discountAmount := roundTo2(bookingTotal * rdPercent / 100)
if _, err := q.Exec(ctx, `