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

  1. Verify the role seeding migration ran and an owner-role row exists in the roles table
  2. Check server logs for the wrapped GetOrgOwnerRoleId error to pinpoint query vs connection failure
  3. Confirm DB connectivity, then retry
  4. 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

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


AI-assisted analysis of plandex-ai/plandex@e2d772072e (2026-09-05). Data as JSON: /api/errors/9f8fcd2ff1bcb9b1. Report an issue: GitHub.