{"record":{"id":"b5f5bc168c0f5c2d","repo":"Billionmail/BillionMail","slug":"failed-to-get-account-w","errorCode":null,"errorMessage":"failed to get account: %w","messagePattern":"failed to get account: %w","errorType":"error_code","errorClass":null,"httpStatus":null,"severity":"critical","filePath":"core/internal/service/rbac/account.go","lineNumber":326,"sourceCode":"\n\troles, ok := value.([]string)\n\tif !ok {\n\t\treturn []string{}\n\t}\n\n\treturn roles\n}\n\n// GetCurrentAccount gets the current user account from context\nfunc GetCurrentAccount(ctx context.Context) (acc *model.Account, err error) {\n\taccountId := GetCurrentAccountId(ctx)\n\n\tif accountId == 0 {\n\t\treturn nil, fmt.Errorf(\"account ID not found in context\")\n\t}\n\n\tif err = g.DB().Model(\"account\").Where(\"account_id = ?\", accountId).Scan(&acc); err != nil {\n\t\treturn nil, fmt.Errorf(\"failed to get account: %w\", err)\n\t}\n\n\treturn\n}\n","sourceCodeStart":308,"sourceCodeEnd":331,"githubUrl":"https://github.com/Billionmail/BillionMail/blob/fc36c76c050c3775c5e899faf7403cf0262d2744/core/internal/service/rbac/account.go#L308-L331","documentation":"After extracting the account ID from context, GetCurrentAccount loads the row with g.DB().Model(\"account\").Scan. If the DB query fails, the driver error is wrapped with %w as 'failed to get account: ...'. Unlike 'account ID not found in context', this means the identity was known but the lookup itself failed at the database layer.","triggerScenarios":"Postgres unreachable, account table missing/damaged, or connection timeout while fetching the row for a valid account ID.","commonSituations":"Database outage or restart mid-request; deleted/migrated schema; connection-pool saturation under load causing timeouts.","solutions":["Inspect the wrapped cause after the colon (connection refused, relation does not exist, timeout).","Verify PostgreSQL availability and credentials.","Confirm the account table exists and matches the expected schema.","Check DB pool limits and tune max connections if errors appear under load."],"exampleFix":null,"handlingStrategy":"retry","validationCode":"if err := g.DB().PingContext(ctx); err != nil {\n    return fmt.Errorf(\"database unavailable: %w\", err)\n}","typeGuard":null,"tryCatchPattern":"acc, err := service.GetCurrentAccount(ctx)\nif err != nil {\n    var dErr gdb.Error\n    if errors.As(err, &dErr) || strings.Contains(err.Error(), \"failed to get account\") {\n        return retryBackoff(err) // transient DB failure\n    }\n    return err\n}","preventionTips":["Monitor DB availability and connection-pool saturation.","Set sane connect/read timeouts in the database config.","Run health checks that exercise an account query, not just a ping.","Apply schema migrations consistently across environments."],"tags":["database","postgres","rbac","auth"],"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"}