Billionmail/BillionMail · critical
failed to get account: %w
Error message
failed to get account: %w
What it means
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.
Source
Thrown at core/internal/service/rbac/account.go:326
roles, ok := value.([]string)
if !ok {
return []string{}
}
return roles
}
// GetCurrentAccount gets the current user account from context
func GetCurrentAccount(ctx context.Context) (acc *model.Account, err error) {
accountId := GetCurrentAccountId(ctx)
if accountId == 0 {
return nil, fmt.Errorf("account ID not found in context")
}
if err = g.DB().Model("account").Where("account_id = ?", accountId).Scan(&acc); err != nil {
return nil, fmt.Errorf("failed to get account: %w", err)
}
return
}
View on GitHub (pinned to fc36c76c05)
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.
Defensive patterns
Strategy: retry
Validate before calling
if err := g.DB().PingContext(ctx); err != nil {
return fmt.Errorf("database unavailable: %w", err)
} Try / catch
acc, err := service.GetCurrentAccount(ctx)
if err != nil {
var dErr gdb.Error
if errors.As(err, &dErr) || strings.Contains(err.Error(), "failed to get account") {
return retryBackoff(err) // transient DB failure
}
return err
} Prevention
- 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.
When it happens
Trigger: Postgres unreachable, account table missing/damaged, or connection timeout while fetching the row for a valid account ID.
Common situations: Database outage or restart mid-request; deleted/migrated schema; connection-pool saturation under load causing timeouts.
Understand the failure class
Background: Database query failed: Internal Server Error 500s wrapping SQL, Prisma, and connection failures — what to check first — this error's family across 16 libraries.
Related errors
- Failed to get account roles
- Failed to get the total number of exception recipients: %w
- Failed to get the exception recipient list: %w
- failed to get option from database:
- account ID not found in context
AI-assisted analysis of Billionmail/BillionMail@fc36c76c05 (2026-09-05).
Data as JSON: /api/errors/b5f5bc168c0f5c2d.
Report an issue: GitHub.