{"record":{"id":"ef082799bdba06fa","repo":"plandex-ai/plandex","slug":"error-listing-org-users-err-error","errorCode":null,"errorMessage":"Error listing org users: {err.Error()}","messagePattern":"Error listing org users: (.+?)","errorType":"http","errorClass":null,"httpStatus":500,"severity":"error","filePath":"app/server/handlers/users.go","lineNumber":66,"sourceCode":"\t\treturn\n\t}\n\n\tusers, err := db.ListUsers(auth.OrgId)\n\tif err != nil {\n\t\tlog.Println(\"Error listing users: \", err)\n\t\thttp.Error(w, \"Error listing users: \"+err.Error(), http.StatusInternalServerError)\n\t\treturn\n\t}\n\n\tapiUsers := make([]*shared.User, 0, len(users))\n\tfor _, user := range users {\n\t\tapiUsers = append(apiUsers, user.ToApi())\n\t}\n\n\torgUsers, err := db.ListOrgUsers(auth.OrgId)\n\tif err != nil {\n\t\tlog.Println(\"Error listing org users: \", err)\n\t\thttp.Error(w, \"Error listing org users: \"+err.Error(), http.StatusInternalServerError)\n\t\treturn\n\t}\n\n\torgUsersByUserId := make(map[string]*shared.OrgUser)\n\tfor _, orgUser := range orgUsers {\n\t\torgUsersByUserId[orgUser.UserId] = orgUser.ToApi()\n\t}\n\n\tresp := shared.ListUsersResponse{\n\t\tUsers:            apiUsers,\n\t\tOrgUsersByUserId: orgUsersByUserId,\n\t}\n\n\tbytes, err := json.Marshal(resp)\n\n\tif err != nil {\n\t\tlog.Println(\"Error marshalling users: \", err)\n\t\thttp.Error(w, \"Error marshalling users: \"+err.Error(), http.StatusInternalServerError)","sourceCodeStart":48,"sourceCodeEnd":84,"githubUrl":"https://github.com/plandex-ai/plandex/blob/e2d772072efadbe41d2946d97d79be55532dbab5/app/server/handlers/users.go#L48-L84","documentation":"ListUsersHandler then calls db.ListOrgUsers(auth.OrgId) to fetch org-membership records, mapping them by UserId for the response. A failure here returns 500 'Error listing org users: <err>' with the raw DB error appended.","triggerScenarios":"GET users list when the org_users query fails: DB down, org_users table schema drift, foreign-key rows referencing deleted users, or connection/context issues mid-request.","commonSituations":"Orphaned org_users rows after user deletion without cascading cleanup; unapplied migrations altering the org_users table; transient DB connectivity loss during the request.","solutions":["Inspect the raw DB error in the response body or server log","Run pending migrations so org_users schema matches the code","Clean up orphaned org_users rows pointing at deleted users","Verify DB health and retry the request"],"exampleFix":null,"handlingStrategy":"retry","validationCode":null,"typeGuard":null,"tryCatchPattern":"try {\n  return await api.listUsers();\n} catch (e) {\n  if (e.status === 500 && /Error listing org users/.test(e.message)) {\n    await backoffRetry(() => api.listUsers(), 3);\n  } else throw e;\n}","preventionTips":["Use ON DELETE CASCADE or cleanup jobs for org_users rows","Keep org_users migrations in sync with deploys","Check server logs for the raw DB error appended to the 500 body","Retry transient DB failures with backoff"],"tags":["database","http-500","org-users"],"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-14T00:17:10.932Z"}