{"record":{"id":"eb8db75abc7f4400","repo":"Billionmail/BillionMail","slug":"failed-to-get-the-total-number-of-exception-recipi","errorCode":null,"errorMessage":"Failed to get the total number of exception recipients: %w","messagePattern":"Failed to get the total number of exception recipients: %w","errorType":"exception","errorClass":null,"httpStatus":null,"severity":"error","filePath":"core/internal/service/abnormal_recipient/abnormal_recipient.go","lineNumber":33,"sourceCode":"\tif page <= 0 {\n\t\tpage = 1\n\t}\n\tif pageSize <= 0 {\n\t\tpageSize = 10\n\t}\n\n\tmodel := g.DB().Model(\"abnormal_recipient\").Safe()\n\n\tif keyword != \"\" {\n\t\tmodel = model.WhereLike(\"recipient\", \"%\"+keyword+\"%\")\n\t}\n\tif addType > 0 {\n\t\tmodel = model.Where(\"add_type\", addType)\n\t}\n\n\ttotal, err = model.Count()\n\tif err != nil {\n\t\treturn 0, nil, fmt.Errorf(\"Failed to get the total number of exception recipients: %w\", err)\n\t}\n\n\tlist = make([]*entity.AbnormalRecipient, 0)\n\terr = model.Page(page, pageSize).\n\t\tOrder(\"create_time DESC\").\n\t\tScan(&list)\n\n\tif err != nil {\n\t\treturn 0, nil, fmt.Errorf(\"Failed to get the exception recipient list: %w\", err)\n\t}\n\n\treturn total, list, nil\n}\n\nfunc Add(ctx context.Context, recipient string) error {\n\n\tnow := time.Now().Unix()\n\t_, err := g.DB().Model(\"abnormal_recipient\").","sourceCodeStart":15,"sourceCodeEnd":51,"githubUrl":"https://github.com/Billionmail/BillionMail/blob/fc36c76c050c3775c5e899faf7403cf0262d2744/core/internal/service/abnormal_recipient/abnormal_recipient.go#L15-L51","documentation":"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.","triggerScenarios":"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.","commonSituations":"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.","solutions":["Check the wrapped %w error for the root DB cause (relation does not exist, connection refused, auth).","Run pending database migrations to ensure the abnormal_recipient table exists.","Verify DB connectivity and credentials in the GoFrame config.","Retry if transient (connection pool exhaustion); add connection-pool health checks."],"exampleFix":"// before\n// table not migrated\ncurl API -> 500 Failed to get the total number of exception recipients\n// after\n# apply migrations, then\ncurl API -> 200 {total: 42, list: [...] }","handlingStrategy":"try-catch","validationCode":"// pre-flight: ensure table exists before calling the API\nvar exists bool\n_ = db.QueryRow(`SELECT EXISTS (SELECT FROM information_schema.tables WHERE table_name='abnormal_recipient')`).Scan(&exists)\nif !exists { runMigrations() }","typeGuard":null,"tryCatchPattern":"total, list, err := abnormal_recipient.GetListWithPage(ctx, page, pageSize, addType)\nif err != nil {\n  if strings.Contains(err.Error(), \"total number\") {\n    // count query failed: likely DB down or table missing — check wrapped cause\n    log.Printf(\"abnormal recipient count failed: %v\", err)\n  }\n  return err\n}","preventionTips":["Run migrations on every deploy before traffic","Monitor DB connectivity and pool saturation","Set sensible connection-retry/backoff in the DB config","Verify credentials and schema in each environment (dev/staging/prod)"],"tags":["database","postgres","query"],"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-12T22:17:10.623Z"}