{"record":{"id":"7eef562acf307ede","repo":"Billionmail/BillionMail","slug":"failed-to-add-exception-recipient-w","errorCode":null,"errorMessage":"Failed to add exception recipient: %w","messagePattern":"Failed to add exception recipient: %w","errorType":"exception","errorClass":null,"httpStatus":null,"severity":"error","filePath":"core/internal/service/abnormal_recipient/abnormal_recipient.go","lineNumber":62,"sourceCode":"\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\").\n\t\tData(g.Map{\n\t\t\t\"recipient\":   recipient,\n\t\t\t\"count\":       3,\n\t\t\t\"add_type\":    1,\n\t\t\t\"description\": \"Manually added\",\n\t\t\t\"create_time\": now,\n\t\t}).\n\t\tInsertIgnore()\n\n\tif err != nil {\n\t\treturn fmt.Errorf(\"Failed to add exception recipient: %w\", err)\n\t}\n\n\treturn nil\n}\n\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","sourceCodeStart":44,"sourceCodeEnd":80,"githubUrl":"https://github.com/Billionmail/BillionMail/blob/fc36c76c050c3775c5e899faf7403cf0262d2744/core/internal/service/abnormal_recipient/abnormal_recipient.go#L44-L80","documentation":"Add inserts a manually-added recipient into the abnormal_recipient table with InsertIgnore. When the underlying SQL INSERT fails (connection loss, schema mismatch, permission denial, driver error), the raw driver error is wrapped with this message and returned to the caller AddAbnormalRecipient.","triggerScenarios":"Calling Add(ctx, recipient) when the PostgreSQL server is unreachable, the abnormal_recipient table/columns are missing or renamed, or the DB user lacks INSERT privilege on the table.","commonSituations":"Fresh deployments where migrations have not created abnormal_recipient yet; docker-compose where the postgres container is not up; schema drift after an upgrade that renamed add_type/description columns.","solutions":["Verify the database is reachable and the abnormal_recipient table exists (run migrations).","Unwrap the %w error to see the driver message (pq: relation \"abnormal_recipient\" does not exist, etc.) and fix accordingly.","Check INSERT privileges for the configured DB user.","Retry once on transient connection errors."],"exampleFix":"// before\nerr := abnormal_recipient.Add(ctx, \"user@example.com\")\nif err != nil { log.Print(err) }\n// after\nif err := public.EnsureAbnormalRecipientTable(ctx); err != nil { return err }\nif err := abnormal_recipient.Add(ctx, \"user@example.com\"); err != nil {\n\treturn fmt.Errorf(\"add abnormal recipient: %w\", err)\n}","handlingStrategy":"validation","validationCode":"// before calling Add\nif recipient == \"\" { return errors.New(\"recipient required\") }\nif !g.DB().TableFields(\"abnormal_recipient\") { /* table missing -> run migrations first */ }","typeGuard":null,"tryCatchPattern":"if err := abnormal_recipient.Add(ctx, r); err != nil {\n\tvar gerr gerror.Error\n\tif errors.As(err, &gerr) { logger.Error(ctx, gerr.Error()) }\n\treturn fmt.Errorf(\"add recipient: %w\", err)\n}","preventionTips":["Run migrations before starting the service","Health-check the DB at startup","Log the wrapped error with context (recipient, addType)"],"tags":["database","goframe","insert-failure"],"backgroundTag":"database-insert-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"}