{"record":{"id":"bce84d5807e0a0cd","repo":"plandex-ai/plandex","slug":"error-getting-invites-and-org-names-for-email-v","errorCode":null,"errorMessage":"error getting invites and org names for email: %v","messagePattern":"error getting invites and org names for email: (.+?)","errorType":"exception","errorClass":null,"httpStatus":null,"severity":"error","filePath":"app/server/db/invite_helpers.go","lineNumber":94,"sourceCode":"\terr := Conn.Select(&invites, \"SELECT * FROM invites WHERE org_id = $1 AND accepted_at IS NOT NULL\", orgId)\n\n\tif err != nil {\n\t\treturn nil, fmt.Errorf(\"error getting accepted invites for org: %v\", err)\n\t}\n\n\treturn invites, nil\n}\n\nfunc GetPendingInvitesForEmail(email string) ([]*Invite, error) {\n\temail = strings.ToLower(email)\n\tvar invites []*Invite\n\terr := Conn.Select(&invites, \"SELECT * FROM invites WHERE email = $1 AND accepted_at IS NULL\", email)\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 invites and org names for email: %v\", err)\n\t}\n\n\treturn invites, nil\n}\n\nfunc DeleteInvite(id string, tx *sqlx.Tx) error {\n\tquery := \"DELETE FROM invites WHERE id = $1\"\n\tvar err error\n\n\tif tx == nil {\n\t\t_, err = Conn.Exec(query, id)\n\t} else {\n\t\t_, err = tx.Exec(query, id)\n\t}\n\n\tif err != nil {\n\t\treturn fmt.Errorf(\"error deleting invite: %v\", err)\n\t}","sourceCodeStart":76,"sourceCodeEnd":112,"githubUrl":"https://github.com/plandex-ai/plandex/blob/e2d772072efadbe41d2946d97d79be55532dbab5/app/server/db/invite_helpers.go#L76-L112","documentation":"GetPendingInvitesForEmail selects unaccepted invites for an email address, used by GetAccessibleOrgsForUser to compute which orgs a user can join. sql.ErrNoRows is treated as 'no invites'; other errors are wrapped with this (slightly misleading) message about 'org names'. It is a DB failure of the pending-invites-by-email query.","triggerScenarios":"Conn.Select(\"SELECT * FROM invites WHERE email = $1 AND accepted_at IS NULL\", email) fails with non-ErrNoRows: DB unreachable, statement timeout, schema drift causing scan failures, or email value that can't bind to the column type.","commonSituations":"User login/org-access computation during a DB outage; invites table altered by migration while old binaries run; empty email string passed accidentally (usually yields empty result, not error, but can surface binding issues).","solutions":["Inspect the wrapped driver error to distinguish connectivity from schema problems.","Run outstanding migrations if the error mentions unknown columns.","Verify database connectivity/retry transient outages upstream.","Normalize the email (trim/lowercase) before lookup to match stored rows.","Remember nil,nil means 'no pending invites' — handle before treating errors."],"exampleFix":"// before\ninvites, err := db.GetPendingInvitesForEmail(email)\nif err != nil {\n    return nil, err\n}\n\n// after\ninvites, err := db.GetPendingInvitesForEmail(strings.ToLower(strings.TrimSpace(email)))\nif err != nil {\n    return nil, fmt.Errorf(\"pending invites lookup: %w\", err)\n}","handlingStrategy":"try-catch","validationCode":"func validEmail(email string) bool {\n    _, err := mail.ParseAddress(strings.TrimSpace(email))\n    return err == nil\n}","typeGuard":"func hasPendingInvites(invites []*db.Invite, err error) bool {\n    return err == nil && len(invites) > 0\n}","tryCatchPattern":"invites, err := db.GetPendingInvitesForEmail(email)\nif err != nil {\n    // DB failure during org-access computation; fail closed or degrade gracefully\n    logger.Error(\"pending invites lookup failed\", \"err\", err)\n    return nil, fmt.Errorf(\"org access unavailable: %w\", err)\n}\n// nil,nil means no pending invites","preventionTips":["Normalize emails before storing and querying.","Apply migrations before code that expects new columns.","Cache org-access lookups to reduce blast radius of DB hiccups at login.","Distinguish the nil,nil 'no invites' path from errors in every caller.","Alert on failures in this path — it blocks user authentication/access flows."],"tags":["database","sql","select","email-lookup"],"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"}