{"record":{"id":"77c52726542bbe97","repo":"Billionmail/BillionMail","slug":"failed-to-get-exception-recipient-w","errorCode":null,"errorMessage":"Failed to get exception recipient: %w","messagePattern":"Failed to get exception recipient: %w","errorType":"exception","errorClass":null,"httpStatus":null,"severity":"error","filePath":"core/internal/service/abnormal_recipient/abnormal_recipient.go","lineNumber":85,"sourceCode":"\nfunc Delete(ctx context.Context, id int) error {\n\n\t_, err := g.DB().Model(\"abnormal_recipient\").\n\t\tWhere(\"id\", id).\n\t\tDelete()\n\n\tif err != nil {\n\t\treturn fmt.Errorf(\"Failed to remove exception recipient: %w\", err)\n\t}\n\n\treturn nil\n}\n\nfunc GetAbnormalRecipient(ctx context.Context, id int) (*entity.AbnormalRecipient, error) {\n\tvar recipient entity.AbnormalRecipient\n\terr := g.DB().Model(\"abnormal_recipient\").Where(\"id\", id).Scan(&recipient)\n\tif err != nil {\n\t\treturn nil, fmt.Errorf(\"Failed to get exception recipient: %w\", err)\n\t}\n\treturn &recipient, nil\n}\n\nfunc BatchUpsertAbnormalRecipients(ctx context.Context, recipients []string, addType int, description string) error {\n\tnow := time.Now().Unix()\n\n\tif len(recipients) == 0 {\n\t\treturn nil\n\t}\n\n\tvar existList []entity.AbnormalRecipient\n\terr := g.DB().Model(\"abnormal_recipient\").WhereIn(\"recipient\", recipients).Scan(&existList)\n\tif err != nil {\n\t\treturn fmt.Errorf(\"Failed to query existing abnormal recipients: %w\", err)\n\t}\n\texistMap := make(map[string]*entity.AbnormalRecipient)\n\tfor _, r := range existList {","sourceCodeStart":67,"sourceCodeEnd":103,"githubUrl":"https://github.com/Billionmail/BillionMail/blob/fc36c76c050c3775c5e899faf7403cf0262d2744/core/internal/service/abnormal_recipient/abnormal_recipient.go#L67-L103","documentation":"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.","triggerScenarios":"Calling GetAbnormalRecipient(ctx, id) while the DB is unreachable, the schema drifted, or the driver cannot map the result set into the entity.","commonSituations":"Missing migration on a fresh install; column renamed after an upgrade; nil/failed DB handle from misconfigured config.yaml database section.","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."],"exampleFix":"// before\nr, err := abnormal_recipient.GetAbnormalRecipient(ctx, id)\nif err != nil { return err }\n// after\nr, err := abnormal_recipient.GetAbnormalRecipient(ctx, id)\nif err != nil { return fmt.Errorf(\"load recipient %d: %w\", id, err) }\nif r.Id == 0 { return gerror.New(\"recipient not found\") }","handlingStrategy":"type-guard","validationCode":"// before calling Get\nif id <= 0 { return errors.New(\"invalid id\") }","typeGuard":"func recipientFound(r *entity.AbnormalRecipient) bool {\n\treturn r != nil && r.Id > 0\n}","tryCatchPattern":"r, err := abnormal_recipient.GetAbnormalRecipient(ctx, id)\nif err != nil { return fmt.Errorf(\"get recipient: %w\", err) }\nif !recipientFound(r) { return gerror.Newf(\"recipient %d not found\", id) }","preventionTips":["Distinguish SQL errors (err) from not-found (zero entity)","Keep entity fields in sync with table schema","Alert on repeated DB query failures"],"tags":["database","goframe","query-failure"],"backgroundTag":"database-query-failed","analyzedSha":"fc36c76c050c3775c5e899faf7403cf0262d2744","analyzedAt":"2026-09-05T21:28:54.019Z","contentChangedAt":"2026-09-05T21:28:54.019Z","schemaVersion":2},"datasetVersion":"2026-09-14T00:17:10.932Z"}