{"record":{"id":"a7b44ecf3a9907d6","repo":"plandex-ai/plandex","slug":"error-listing-org-roles-v","errorCode":null,"errorMessage":"error listing org roles: %v","messagePattern":"error listing org roles: (.+?)","errorType":"exception","errorClass":null,"httpStatus":null,"severity":"error","filePath":"app/server/db/org_helpers.go","lineNumber":214,"sourceCode":"\tif tx == nil {\n\t\t_, err = Conn.Exec(query, orgId, userId, orgRoleId)\n\t} else {\n\t\t_, err = tx.Exec(query, orgId, userId, orgRoleId)\n\t}\n\n\tif err != nil {\n\t\treturn fmt.Errorf(\"error adding org member: %v\", err)\n\t}\n\n\treturn nil\n}\n\nfunc ListOrgRoles(orgId string) ([]*OrgRole, error) {\n\tvar orgRoles []*OrgRole\n\terr := Conn.Select(&orgRoles, \"SELECT * FROM org_roles WHERE org_id IS NULL OR org_id = $1\", orgId)\n\n\tif err != nil {\n\t\treturn nil, fmt.Errorf(\"error listing org roles: %v\", err)\n\t}\n\n\treturn orgRoles, nil\n}\n\nfunc AddToOrgForDomain(userId, domain string, tx *sqlx.Tx) (string, error) {\n\torg, err := GetOrgForDomain(domain)\n\n\tif err != nil {\n\t\treturn \"\", fmt.Errorf(\"error getting org for domain: %v\", err)\n\t}\n\n\torgOwnerRoleId, err := GetOrgOwnerRoleId()\n\n\tif err != nil {\n\t\treturn \"\", fmt.Errorf(\"error getting org owner role id: %v\", err)\n\t}\n","sourceCodeStart":196,"sourceCodeEnd":232,"githubUrl":"https://github.com/plandex-ai/plandex/blob/e2d772072efadbe41d2946d97d79be55532dbab5/app/server/db/org_helpers.go#L196-L232","documentation":"ListOrgRoles wraps a failure of `SELECT * FROM org_roles WHERE org_id IS NULL OR org_id = $1` (sqlx Conn.Select) with this message. It is a query/scan/connection failure surfaced to ListOrgRolesHandler, not an empty-result condition — an empty role set returns (nil, nil).","triggerScenarios":"ListOrgRoles is called with any orgId while the org_roles table is missing, the query is malformed for the live schema (e.g. migration not applied), the DB connection is broken, or a column cannot be scanned into *OrgRole.","commonSituations":"Running the server against a database with pending migrations; connecting to the wrong database/environment; connection pool exhausted after a Postgres restart; schema drift after an upgrade added/renamed columns.","solutions":["Read the wrapped cause: 'relation \"org_roles\" does not exist' means run database migrations","Confirm the server is pointed at the intended DATABASE_URL environment (dev vs prod)","Check DB connectivity/pool health and retry the request","Verify the OrgRole struct fields match the org_roles columns (sqlx scan errors)"],"exampleFix":"// before\nroles, err := ListOrgRoles(orgId)\n// after: surface a clear handler error and check migrations first\nif err != nil {\n    log.Printf(\"ListOrgRoles failed: %v\", err) // inspect cause\n    http.Error(w, \"failed to list org roles; ensure migrations are applied\", http.StatusInternalServerError)\n    return\n}","handlingStrategy":"retry","validationCode":"// verify DB reachable and table present before querying\nvar one int\nif err := Conn.Get(&one, \"SELECT 1 FROM org_roles LIMIT 1\"); err != nil {\n    log.Printf(\"org_roles unavailable (migrations applied?): %v\", err)\n}","typeGuard":null,"tryCatchPattern":"roles, err := ListOrgRoles(orgId)\nif err != nil {\n    log.Printf(\"ListOrgRoles: %v\", err) // preserve cause for triage\n    http.Error(w, \"unable to list roles\", http.StatusInternalServerError)\n    return\n}","preventionTips":["Run migrations as part of every deploy/startup","Pin DATABASE_URL per environment and verify at boot with a SELECT 1 probe","Keep the OrgRole struct in sync with the org_roles schema","Monitor connection-pool saturation and Postgres restarts"],"tags":["database","postgres","sqlx","query","go"],"backgroundTag":"postgres-query-failed","analyzedSha":"e2d772072efadbe41d2946d97d79be55532dbab5","analyzedAt":"2026-09-05T20:56:53.631Z","contentChangedAt":"2026-09-05T20:56:53.631Z","schemaVersion":2},"datasetVersion":"2026-09-14T00:17:10.932Z"}