Billionmail/BillionMail · error
Failed to get exception recipient: %w
Error message
Failed to get exception recipient: %w
What it means
GetAbnormalRecipient scans a single abnormal_recipient row into entity.AbnormalRecipient. If the SELECT fails at the SQL level (connection error, missing table/column, Scan target mismatch), it returns this wrapped error. Note: a not-found id yields a zero-value recipient, not this error.
Source
Thrown at core/internal/service/abnormal_recipient/abnormal_recipient.go:85
func Delete(ctx context.Context, id int) error {
_, err := g.DB().Model("abnormal_recipient").
Where("id", id).
Delete()
if err != nil {
return fmt.Errorf("Failed to remove exception recipient: %w", err)
}
return nil
}
func GetAbnormalRecipient(ctx context.Context, id int) (*entity.AbnormalRecipient, error) {
var recipient entity.AbnormalRecipient
err := g.DB().Model("abnormal_recipient").Where("id", id).Scan(&recipient)
if err != nil {
return nil, fmt.Errorf("Failed to get exception recipient: %w", err)
}
return &recipient, nil
}
func BatchUpsertAbnormalRecipients(ctx context.Context, recipients []string, addType int, description string) error {
now := time.Now().Unix()
if len(recipients) == 0 {
return nil
}
var existList []entity.AbnormalRecipient
err := g.DB().Model("abnormal_recipient").WhereIn("recipient", recipients).Scan(&existList)
if err != nil {
return fmt.Errorf("Failed to query existing abnormal recipients: %w", err)
}
existMap := make(map[string]*entity.AbnormalRecipient)
for _, r := range existList {View on GitHub (pinned to fc36c76c05)
Solutions
- Check database reachability and run pending migrations.
- Compare entity.AbnormalRecipient fields with the actual table columns.
- Fix DB config (host/port/password) if connection errors are the root cause.
- Handle the empty-recipient case separately from the SQL error case.
Example fix
// before
r, err := abnormal_recipient.GetAbnormalRecipient(ctx, id)
if err != nil { return err }
// after
r, err := abnormal_recipient.GetAbnormalRecipient(ctx, id)
if err != nil { return fmt.Errorf("load recipient %d: %w", id, err) }
if r.Id == 0 { return gerror.New("recipient not found") } Defensive patterns
Strategy: type-guard
Validate before calling
// before calling Get
if id <= 0 { return errors.New("invalid id") } Type guard
func recipientFound(r *entity.AbnormalRecipient) bool {
return r != nil && r.Id > 0
} Try / catch
r, err := abnormal_recipient.GetAbnormalRecipient(ctx, id)
if err != nil { return fmt.Errorf("get recipient: %w", err) }
if !recipientFound(r) { return gerror.Newf("recipient %d not found", id) } Prevention
- Distinguish SQL errors (err) from not-found (zero entity)
- Keep entity fields in sync with table schema
- Alert on repeated DB query failures
When it happens
Trigger: Calling GetAbnormalRecipient(ctx, id) while the DB is unreachable, the schema drifted, or the driver cannot map the result set into the entity.
Common situations: Missing migration on a fresh install; column renamed after an upgrade; nil/failed DB handle from misconfigured config.yaml database section.
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
- Failed to query existing abnormal recipients: %w
- Failed to add exception recipient: %w
- Failed to remove exception recipient: %w
- Failed to update abnormal recipient: %w
- Failed to insert abnormal recipients: %w
AI-assisted analysis of Billionmail/BillionMail@fc36c76c05 (2026-09-05).
Data as JSON: /api/errors/77c52726542bbe97.
Report an issue: GitHub.