{"record":{"id":"9f8fcd2ff1bcb9b1","repo":"plandex-ai/plandex","slug":"error-getting-org-owner-role-id-err-error","errorCode":null,"errorMessage":"Error getting org owner role id: {err.Error()}","messagePattern":"Error getting org owner role id: (.+?)","errorType":"http","errorClass":null,"httpStatus":500,"severity":"error","filePath":"app/server/handlers/users.go","lineNumber":167,"sourceCode":"\tisMember, err := db.ValidateOrgMembership(userId, auth.OrgId)\n\n\tif err != nil {\n\t\tlog.Printf(\"Error validating org membership: %v\\n\", err)\n\t\thttp.Error(w, \"Error validating org membership: \"+err.Error(), http.StatusInternalServerError)\n\t\treturn\n\t}\n\n\tif !isMember {\n\t\tlog.Printf(\"User %s is not a member of org %s\\n\", userId, auth.OrgId)\n\t\thttp.Error(w, \"User \"+userId+\" is not a member of org \"+auth.OrgId, http.StatusForbidden)\n\t\treturn\n\t}\n\n\torgOwnerRoleId, err := db.GetOrgOwnerRoleId()\n\n\tif err != nil {\n\t\tlog.Printf(\"Error getting org owner role id: %v\\n\", err)\n\t\thttp.Error(w, \"Error getting org owner role id: \"+err.Error(), http.StatusInternalServerError)\n\t\treturn\n\t}\n\n\t// verify user isn't the only org owner\n\tif orgUser.OrgRoleId == orgOwnerRoleId {\n\t\tnumOwners, err := db.NumUsersWithRole(auth.OrgId, orgOwnerRoleId)\n\n\t\tif err != nil {\n\t\t\tlog.Printf(\"Error getting number of org owners: %v\\n\", err)\n\t\t\thttp.Error(w, \"Error getting number of org owners: \"+err.Error(), http.StatusInternalServerError)\n\t\t\treturn\n\t\t}\n\n\t\tif numOwners == 1 {\n\t\t\tlog.Println(\"Cannot delete the only org owner\")\n\t\t\thttp.Error(w, \"Cannot delete the only org owner\", http.StatusForbidden)\n\t\t\treturn\n\t\t}","sourceCodeStart":149,"sourceCodeEnd":185,"githubUrl":"https://github.com/plandex-ai/plandex/blob/e2d772072efadbe41d2946d97d79be55532dbab5/app/server/handlers/users.go#L149-L185","documentation":"db.GetOrgOwnerRoleId() failed to return the org owner role identifier. Because this role id is a prerequisite for the 'cannot delete last owner' safety check, the handler aborts with HTTP 500 before any deletion occurs.","triggerScenarios":"GetOrgOwnerRoleId errors — the roles table lacks a row marking the owner role, the lookup query fails, or the DB is unreachable.","commonSituations":"Fresh deployment where the role-seed migration didn't run (no owner role row seeded); renamed/mis-migrated org_roles table; DB outage mid-request.","solutions":["Verify the role seeding migration ran and an owner-role row exists in the roles table","Check server logs for the wrapped GetOrgOwnerRoleId error to pinpoint query vs connection failure","Confirm DB connectivity, then retry","Cache the owner role id at startup if the lookup is expensive and the DB is flaky"],"exampleFix":null,"handlingStrategy":"fallback","validationCode":"var ownerRoleExists bool\nerr := db.Get(&ownerRoleExists, \"SELECT EXISTS(SELECT 1 FROM roles WHERE is_owner = true)\")\nif err == nil && !ownerRoleExists {\n    return errors.New(\"owner role not seeded; run migrations\")\n}","typeGuard":null,"tryCatchPattern":"orgOwnerRoleId, err := db.GetOrgOwnerRoleId()\nif err != nil {\n    http.Error(w, \"internal error\", http.StatusInternalServerError)\n    return\n}","preventionTips":["Ensure role-seed migrations run on every deploy and fresh environment","Verify the owner role row exists in CI with a migration smoke test","Log the underlying error rather than echoing DB internals to clients","Optionally cache the owner role id (it rarely changes) with a startup load"],"tags":["go","database","roles","seeding","http-500"],"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"}