plandex-ai/plandex · error
Error getting org owner role id: {err.Error()}
Error message
Error getting org owner role id: {err.Error()} What it means
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.
Source
Thrown at app/server/handlers/users.go:167
isMember, err := db.ValidateOrgMembership(userId, auth.OrgId)
if err != nil {
log.Printf("Error validating org membership: %v\n", err)
http.Error(w, "Error validating org membership: "+err.Error(), http.StatusInternalServerError)
return
}
if !isMember {
log.Printf("User %s is not a member of org %s\n", userId, auth.OrgId)
http.Error(w, "User "+userId+" is not a member of org "+auth.OrgId, http.StatusForbidden)
return
}
orgOwnerRoleId, err := db.GetOrgOwnerRoleId()
if err != nil {
log.Printf("Error getting org owner role id: %v\n", err)
http.Error(w, "Error getting org owner role id: "+err.Error(), http.StatusInternalServerError)
return
}
// verify user isn't the only org owner
if orgUser.OrgRoleId == orgOwnerRoleId {
numOwners, err := db.NumUsersWithRole(auth.OrgId, orgOwnerRoleId)
if err != nil {
log.Printf("Error getting number of org owners: %v\n", err)
http.Error(w, "Error getting number of org owners: "+err.Error(), http.StatusInternalServerError)
return
}
if numOwners == 1 {
log.Println("Cannot delete the only org owner")
http.Error(w, "Cannot delete the only org owner", http.StatusForbidden)
return
}View on GitHub (pinned to e2d772072e)
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
Defensive patterns
Strategy: fallback
Validate before calling
var ownerRoleExists bool
err := db.Get(&ownerRoleExists, "SELECT EXISTS(SELECT 1 FROM roles WHERE is_owner = true)")
if err == nil && !ownerRoleExists {
return errors.New("owner role not seeded; run migrations")
} Try / catch
orgOwnerRoleId, err := db.GetOrgOwnerRoleId()
if err != nil {
http.Error(w, "internal error", http.StatusInternalServerError)
return
} Prevention
- 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
When it happens
Trigger: GetOrgOwnerRoleId errors — the roles table lacks a row marking the owner role, the lookup query fails, or the DB is unreachable.
Common situations: 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.
Understand the failure class
Background: Database query failed: Internal Server Error 500s wrapping SQL, Prisma, and connection failures — what to check first — this error's family across 16 libraries.
Related errors
- error getting current plan state params: %v
- error getting contexts: %v
- error validating project
- error validating plan membership
- Error validating org membership:
AI-assisted analysis of plandex-ai/plandex@e2d772072e (2026-09-05).
Data as JSON: /api/errors/9f8fcd2ff1bcb9b1.
Report an issue: GitHub.