{"record":{"id":"75996dc2c80e92c4","repo":"plandex-ai/plandex","slug":"error-getting-org-for-domain-v","errorCode":null,"errorMessage":"error getting org for domain: %v","messagePattern":"error getting org for domain: (.+?)","errorType":"exception","errorClass":null,"httpStatus":null,"severity":"error","filePath":"app/server/db/org_helpers.go","lineNumber":140,"sourceCode":"\n\tif err != nil {\n\t\treturn nil, fmt.Errorf(\"error adding org membership: %v\", err)\n\t}\n\n\treturn org, nil\n}\n\nfunc GetOrgForDomain(domain string) (*Org, error) {\n\tvar org Org\n\tquery := fmt.Sprintf(\"SELECT %s FROM orgs WHERE domain = $1\", orgFields)\n\terr := Conn.Get(&org, query, domain)\n\n\tif err != nil {\n\t\tif err == sql.ErrNoRows {\n\t\t\treturn nil, nil\n\t\t}\n\n\t\treturn nil, fmt.Errorf(\"error getting org for domain: %v\", err)\n\t}\n\n\treturn &org, nil\n}\n\nfunc AddOrgDomainUsers(orgId, domain string, tx *sqlx.Tx) error {\n\tusersForDomain, err := GetUsersForDomain(domain)\n\n\tif err != nil {\n\t\treturn fmt.Errorf(\"error getting users for domain: %v\", err)\n\t}\n\n\torgMemberRoleId, err := GetOrgMemberRoleId()\n\n\tif err != nil {\n\t\treturn fmt.Errorf(\"error getting org member role id: %v\", err)\n\t}\n","sourceCodeStart":122,"sourceCodeEnd":158,"githubUrl":"https://github.com/plandex-ai/plandex/blob/e2d772072efadbe41d2946d97d79be55532dbab5/app/server/db/org_helpers.go#L122-L158","documentation":"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'.","triggerScenarios":"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).","commonSituations":"Postgres restart mid-request; schema drift where orgs columns changed; running server against a database with an older schema.","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"],"exampleFix":null,"handlingStrategy":"try-catch","validationCode":"if domain == \"\" { return errors.New(\"domain required\") }","typeGuard":"// Remember: nil,nil from GetOrgForDomain means 'no org for domain', not an error\nfunc orgNotFoundForDomain(org *db.Org, err error) bool { return err == nil && org == nil }","tryCatchPattern":"org, err := db.GetOrgForDomain(domain)\nif err != nil {\n    log.Printf(\"org lookup by domain failed: %v\", err)\n    return fmt.Errorf(\"org lookup unavailable\")\n}\nif org == nil { /* no org for this domain — normal case */ }","preventionTips":["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"],"tags":["database","postgresql","org-domain"],"backgroundTag":"database-query-failed","analyzedSha":"e2d772072efadbe41d2946d97d79be55532dbab5","analyzedAt":"2026-09-05T20:56:53.631Z","contentChangedAt":"2026-09-05T20:56:53.631Z","schemaVersion":2},"datasetVersion":"2026-09-12T22:17:10.623Z"}