{"record":{"id":"486a1ca9a831503f","repo":"plandex-ai/plandex","slug":"error-getting-invites-for-user-v","errorCode":null,"errorMessage":"error getting invites for user: %v","messagePattern":"error getting invites for user: (.+?)","errorType":"exception","errorClass":null,"httpStatus":null,"severity":"error","filePath":"app/server/db/org_helpers.go","lineNumber":48,"sourceCode":"\t\torgIds = append(orgIds, ou.OrgId)\n\t\torgRoleIdByOrgId[ou.OrgId] = ou.OrgRoleId\n\t}\n\n\tif len(orgIds) > 0 {\n\t\tquery := fmt.Sprintf(\"SELECT %s FROM orgs WHERE id = ANY($1)\", orgFields)\n\t\terr = Conn.Select(&orgs, query, pq.Array(orgIds))\n\t\tif err != nil {\n\t\t\treturn nil, fmt.Errorf(\"error getting orgs for user: %v\", err)\n\t\t}\n\t} else {\n\t\tlog.Println(\"No orgs found for user\")\n\t\treturn orgs, nil\n\t}\n\n\t// access via invitation\n\tinvites, err := GetPendingInvitesForEmail(user.Email)\n\tif err != nil {\n\t\treturn nil, fmt.Errorf(\"error getting invites for user: %v\", err)\n\t}\n\n\torgIds = []string{}\n\tfor _, invite := range invites {\n\t\torgIds = append(orgIds, invite.OrgId)\n\t\torgRoleIdByOrgId[invite.OrgId] = invite.OrgRoleId\n\t}\n\n\tif len(orgIds) > 0 {\n\t\tvar orgsFromInvites []*Org\n\t\tquery := fmt.Sprintf(\"SELECT %s FROM orgs WHERE id = ANY($1)\", orgFields)\n\t\terr = Conn.Select(&orgsFromInvites, query, pq.Array(orgIds))\n\t\tif err != nil {\n\t\t\treturn nil, fmt.Errorf(\"error getting orgs from invites: %v\", err)\n\t\t}\n\t\torgs = append(orgs, orgsFromInvites...)\n\t}\n","sourceCodeStart":30,"sourceCodeEnd":66,"githubUrl":"https://github.com/plandex-ai/plandex/blob/e2d772072efadbe41d2946d97d79be55532dbab5/app/server/db/org_helpers.go#L30-L66","documentation":"GetAccessibleOrgsForUser wraps a failure of GetPendingInvitesForEmail (the invitation-based access lookup) with this message. It is not itself a SQL statement here — it means the pending-invites query errored for the user's email. Zero pending invites is not an error.","triggerScenarios":"GetPendingInvitesForEmail's underlying SELECT on the invites table fails: missing table, DB connection error, or scan mismatch on the invite struct.","commonSituations":"Invites table missing in an environment with stale migrations; invites schema changed (column renamed) breaking the invite struct scan; DB outage during sign-in.","solutions":["Check GetPendingInvitesForEmail and its wrapped error for the real SQL cause","Run pending migrations for the invites table","Align the invite struct db tags with the invites schema","Add retry for transient DB failures"],"exampleFix":"// before\ninvites, err := GetPendingInvitesForEmail(user.Email)\nif err != nil { return nil, fmt.Errorf(\"error getting invites for user: %v\", err) }\n// after\ninvites, err := GetPendingInvitesForEmail(user.Email)\nif err != nil { return nil, fmt.Errorf(\"error getting invites for user (email=%s): %w\", user.Email, err) } // %w preserves the cause for errors.Is/As","handlingStrategy":"try-catch","validationCode":"// ensure user.Email is non-empty before invite lookup\nif user == nil || user.Email == \"\" { return nil, errors.New(\"user email required for invite lookup\") }","typeGuard":"func isInviteLookupError(err error) bool {\n    return err != nil && strings.Contains(err.Error(), \"error getting invites for user\")\n}","tryCatchPattern":"orgs, err := db.GetAccessibleOrgsForUser(user)\nif err != nil {\n    if isInviteLookupError(err) {\n        log.Printf(\"invite lookup failed for %s: %v\", user.Email, err) // inspect Unwrap for the SQL cause\n    }\n    return err\n}","preventionTips":["Ensure GetPendingInvitesForEmail's table exists (migrations) and struct tags match its schema","Use %w instead of %v so root causes remain inspectable","Log the user email (safely) with the failure for triage","Add retry for transient DB errors in sign-in paths","Alert on repeated invite-lookup failures — usually schema or connectivity"],"tags":["database","postgres","sqlx","error-wrapping"],"backgroundTag":"sql-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"}