{"record":{"id":"7c9787d8c31a2d52","repo":"Billionmail/BillionMail","slug":"failed-to-check-alias-existence-v","errorCode":null,"errorMessage":"failed to check alias existence: %v","messagePattern":"failed to check alias existence: (.+?)","errorType":"exception","errorClass":null,"httpStatus":null,"severity":"error","filePath":"core/internal/service/domains/domains.go","lineNumber":54,"sourceCode":"\t\tresult[i] = v1.BlacklistDetail{\n\t\t\tBlacklist: detail.Blacklist,\n\t\t\tResponse:  detail.Response,\n\t\t\tTime:      detail.Time,\n\t\t}\n\t}\n\treturn result\n}\n\nfunc setCatchall(ctx context.Context, domainName, catchall string) error {\n\taddress := fmt.Sprintf(\"@%s\", domainName)\n\tif catchall != \"\" {\n\t\tvar count int\n\t\tcount, err := g.DB().Model(\"alias\").\n\t\t\tWhere(\"address\", address).\n\t\t\tWhere(\"domain\", domainName).\n\t\t\tCount()\n\t\tif err != nil {\n\t\t\treturn fmt.Errorf(\"failed to check alias existence: %v\", err)\n\t\t}\n\t\tif count > 0 {\n\t\t\t_, err = g.DB().Model(\"alias\").\n\t\t\t\tWhere(\"address\", address).\n\t\t\t\tWhere(\"domain\", domainName).\n\t\t\t\tData(g.Map{\"goto\": catchall, \"active\": 1, \"update_time\": time.Now().Unix()}).\n\t\t\t\tUpdate()\n\t\t\tif err != nil {\n\t\t\t\treturn fmt.Errorf(\"failed to update alias: %v\", err)\n\t\t\t}\n\t\t} else {\n\t\t\t_, err = g.DB().Model(\"alias\").Data(g.Map{\n\t\t\t\t\"address\":     address,\n\t\t\t\t\"goto\":        catchall,\n\t\t\t\t\"domain\":      domainName,\n\t\t\t\t\"active\":      1,\n\t\t\t\t\"create_time\": time.Now().Unix(),\n\t\t\t\t\"update_time\": time.Now().Unix(),","sourceCodeStart":36,"sourceCodeEnd":72,"githubUrl":"https://github.com/Billionmail/BillionMail/blob/fc36c76c050c3775c5e899faf7403cf0262d2744/core/internal/service/domains/domains.go#L36-L72","documentation":"setCatchall (called from Add and Update in domains/domains.go) queries the alias table for a row with the given address+domain before inserting or updating the catchall mapping; a database failure during this existence check is wrapped as 'failed to check alias existence: %v'. The %v carries the underlying GoFrame/PostgreSQL error.","triggerScenarios":"Add or Update of a domain with catchall enabled when the query g.DB().Model(\"alias\").Where(\"address\", address).Where(\"domain\", domainName).Count() fails: database down, connection pool exhausted, permission denied on the alias table, table missing (migration not run), lock timeout, or invalid characters in address causing a driver error.","commonSituations":"PostgreSQL restarted or unreachable mid-request; schema migrations not applied so the alias table doesn't exist; DB user lacking SELECT on alias; connection saturation under load; deadlock/lock timeout from a concurrent alias update.","solutions":["Check the wrapped error and PostgreSQL logs (docker logs / journalctl -u postgresql) for the root cause","Verify DB connectivity and that the alias table exists with correct migrations applied","Grant the app DB role SELECT/INSERT/UPDATE on the alias table","Retry the operation once transient connection errors are resolved; check pool settings if saturated"],"exampleFix":"// before\ncount, err := g.DB().Model(\"alias\").\n\tWhere(\"address\", address).\n\tWhere(\"domain\", domainName).\n\tCount()\nif err != nil {\n\treturn fmt.Errorf(\"failed to check alias existence: %v\", err)\n}\n// after\ncount, err := g.DB().Model(\"alias\").\n\tWhere(\"address\", address).\n\tWhere(\"domain\", domainName).\n\tCount()\nif err != nil {\n\treturn fmt.Errorf(\"failed to check alias existence (address=%s domain=%s): %w\", address, domainName, err)\n}","handlingStrategy":"retry","validationCode":"// pre-flight: DB reachable and alias table present\nif err := g.DB().Ping(ctx); err != nil {\n\treturn fmt.Errorf(\"database unreachable: %w\", err)\n}\nif n, err := g.DB().Model(\"alias\").Count(); err != nil {\n\treturn fmt.Errorf(\"alias table not queryable (migrations applied?): %w\", err)\n} else { _ = n }","typeGuard":null,"tryCatchPattern":"err := setCatchall(domainName, catchall)\nif err != nil && strings.Contains(err.Error(), \"failed to check alias existence\") {\n\t// transient DB issue: back off and retry once\n\ttime.Sleep(2 * time.Second)\n\terr = setCatchall(domainName, catchall)\n}","preventionTips":["Run DB migrations on every deploy so the alias table always exists","Monitor PostgreSQL health and connection-pool saturation","Grant the app role explicit privileges on the alias table","Sanitize/normalize address and domain inputs before querying"],"tags":["database","postgresql","alias"],"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"}