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

  1. Read the wrapped %v: if it's a connection error, check Postgres health and connectivity
  2. Run migrations so the orgs table matches the Org struct fields
  3. If it's a scan error, compare the orgs schema with the db.Org struct and fix column types
  4. 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

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


AI-assisted analysis of plandex-ai/plandex@e2d772072e (2026-09-05). Data as JSON: /api/errors/75996dc2c80e92c4. Report an issue: GitHub.