Billionmail/BillionMail · error

Failed to get the total number of exception recipients: %w

Error message

Failed to get the total number of exception recipients: %w

What it means

GetListWithPage counts abnormal (exception/bounced) recipients filtered by the query; when the model.Count() query fails the error is wrapped as 'Failed to get the total number of exception recipients'. This is a database-level failure, not a business-logic error.

Source

Thrown at core/internal/service/abnormal_recipient/abnormal_recipient.go:33

	if page <= 0 {
		page = 1
	}
	if pageSize <= 0 {
		pageSize = 10
	}

	model := g.DB().Model("abnormal_recipient").Safe()

	if keyword != "" {
		model = model.WhereLike("recipient", "%"+keyword+"%")
	}
	if addType > 0 {
		model = model.Where("add_type", addType)
	}

	total, err = model.Count()
	if err != nil {
		return 0, nil, fmt.Errorf("Failed to get the total number of exception recipients: %w", err)
	}

	list = make([]*entity.AbnormalRecipient, 0)
	err = model.Page(page, pageSize).
		Order("create_time DESC").
		Scan(&list)

	if err != nil {
		return 0, nil, fmt.Errorf("Failed to get the exception recipient list: %w", err)
	}

	return total, list, nil
}

func Add(ctx context.Context, recipient string) error {

	now := time.Now().Unix()
	_, err := g.DB().Model("abnormal_recipient").

View on GitHub (pinned to fc36c76c05)

Solutions

  1. Check the wrapped %w error for the root DB cause (relation does not exist, connection refused, auth).
  2. Run pending database migrations to ensure the abnormal_recipient table exists.
  3. Verify DB connectivity and credentials in the GoFrame config.
  4. Retry if transient (connection pool exhaustion); add connection-pool health checks.

Example fix

// before
// table not migrated
curl API -> 500 Failed to get the total number of exception recipients
// after
# apply migrations, then
curl API -> 200 {total: 42, list: [...] }
Defensive patterns

Strategy: try-catch

Validate before calling

// pre-flight: ensure table exists before calling the API
var exists bool
_ = db.QueryRow(`SELECT EXISTS (SELECT FROM information_schema.tables WHERE table_name='abnormal_recipient')`).Scan(&exists)
if !exists { runMigrations() }

Try / catch

total, list, err := abnormal_recipient.GetListWithPage(ctx, page, pageSize, addType)
if err != nil {
  if strings.Contains(err.Error(), "total number") {
    // count query failed: likely DB down or table missing — check wrapped cause
    log.Printf("abnormal recipient count failed: %v", err)
  }
  return err
}

Prevention

When it happens

Trigger: ListAbnormalRecipient called while the abnormal_recipient table is missing, the database is down/unreachable, the connection pool is exhausted, or the addType filter references a column issue in a broken migration state.

Common situations: Fresh install where migrations haven't created the table; Postgres restarted or connection limit reached; wrong DB credentials in config; schema drift after an upgrade.

Understand the failure class

Background: Database query failed: Internal Server Error 500s wrapping SQL, Prisma, and connection failures — what to check first — this error's family across 16 libraries.

Related errors


AI-assisted analysis of Billionmail/BillionMail@fc36c76c05 (2026-09-05). Data as JSON: /api/errors/eb8db75abc7f4400. Report an issue: GitHub.