plandex-ai/plandex · error
error getting org for domain: %v
Error message
error getting org for domain: %v
What it means
GetOrgForDomain wraps any error from its SELECT (other than sql.ErrNoRows, which yields nil,nil) into 'error getting org for domain: %v'. Callers like AddToOrgForDomain surface it verbatim. Note the no-rows case deliberately returns (nil, nil), so this error always indicates a real query failure, not 'org not found'.
Source
Thrown at app/server/db/org_helpers.go:140
if err != nil {
return nil, fmt.Errorf("error adding org membership: %v", err)
}
return org, nil
}
func GetOrgForDomain(domain string) (*Org, error) {
var org Org
query := fmt.Sprintf("SELECT %s FROM orgs WHERE domain = $1", orgFields)
err := Conn.Get(&org, query, domain)
if err != nil {
if err == sql.ErrNoRows {
return nil, nil
}
return nil, fmt.Errorf("error getting org for domain: %v", err)
}
return &org, nil
}
func AddOrgDomainUsers(orgId, domain string, tx *sqlx.Tx) error {
usersForDomain, err := GetUsersForDomain(domain)
if err != nil {
return fmt.Errorf("error getting users for domain: %v", err)
}
orgMemberRoleId, err := GetOrgMemberRoleId()
if err != nil {
return fmt.Errorf("error getting org member role id: %v", err)
}
View on GitHub (pinned to e2d772072e)
Solutions
- Read the wrapped %v: if it's a connection error, check Postgres health and connectivity
- Run migrations so the orgs table matches the Org struct fields
- If it's a scan error, compare the orgs schema with the db.Org struct and fix column types
- Retry the signup/auth flow once the DB is healthy
Defensive patterns
Strategy: try-catch
Validate before calling
if domain == "" { return errors.New("domain required") } Type guard
// Remember: nil,nil from GetOrgForDomain means 'no org for domain', not an error
func orgNotFoundForDomain(org *db.Org, err error) bool { return err == nil && org == nil } Try / catch
org, err := db.GetOrgForDomain(domain)
if err != nil {
log.Printf("org lookup by domain failed: %v", err)
return fmt.Errorf("org lookup unavailable")
}
if org == nil { /* no org for this domain — normal case */ } Prevention
- Handle the (nil, nil) case explicitly — it is not an error
- Keep orgs schema and Org struct in sync via migrations
- Monitor DB connectivity; this surfaces only on real query failures
- Normalize domains (lowercase, trim) before lookup to avoid unexpected no-row results
When it happens
Trigger: SELECT ... FROM orgs WHERE domain = $1 fails: connection error, orgs table missing after failed migration, or Conn.Get/scan mismatch (e.g. schema column type changed and no longer scans into Org).
Common situations: Postgres restart mid-request; schema drift where orgs columns changed; running server against a database with an older schema.
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
- error adding convo tokens: %v
- error checking settings: %v
- error creating postgres driver: %v
- error validating org membership: %v
- an org with domain %s already exists
AI-assisted analysis of plandex-ai/plandex@e2d772072e (2026-09-05).
Data as JSON: /api/errors/75996dc2c80e92c4.
Report an issue: GitHub.