plandex-ai/plandex · error

Error validating org membership: {err.Error()}

Error message

Error validating org membership: {err.Error()}

What it means

db.ValidateOrgMembership(userId, auth.OrgId) returned an error while checking that the target user belongs to the caller's org. This is a DB-level failure (connection, query, or scan), reported as HTTP 500 with the raw error text — distinct from isMember=false, which yields a 403.

Source

Thrown at app/server/handlers/users.go:153

		http.Error(w, "Error getting org user: "+err.Error(), http.StatusInternalServerError)
		return
	}

	// ensure current user can remove target user
	removePermission := shared.Permission(strings.Join([]string{string(shared.PermissionRemoveUser), orgUser.OrgRoleId}, "|"))

	if !auth.HasPermission(removePermission) {
		log.Printf("User does not have permission to remove user with role: %v\n", orgUser.OrgRoleId)
		http.Error(w, "User does not have permission to remove user with role: "+orgUser.OrgRoleId, http.StatusForbidden)
		return
	}

	// verify user is org member
	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

View on GitHub (pinned to e2d772072e)

Solutions

  1. Check server logs for the wrapped error to identify connection vs schema vs timeout causes
  2. Verify DB connectivity and pool health (max connections, idle timeouts)
  3. Confirm the org_users table schema and migrations are intact
  4. Retry the request if the failure was transient (connection blip)
Defensive patterns

Strategy: retry

Validate before calling

if err := db.PingContext(ctx); err != nil {
    return fmt.Errorf("database unavailable: %w", err)
}

Try / catch

isMember, err := db.ValidateOrgMembership(userId, auth.OrgId)
if err != nil {
    if isTransientDBError(err) {
        http.Error(w, "temporarily unavailable, retry", http.StatusServiceUnavailable)
    } else {
        http.Error(w, "internal error", http.StatusInternalServerError)
    }
    return
}

Prevention

When it happens

Trigger: ValidateOrgMembership errors out — DB connection drop mid-request, table/index missing after a migration, or the query times out under load.

Common situations: Postgres restarted or connection pool exhausted during the request; migration rolled the org_users table back; read replica lag or failover in the middle of the call.

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/7267d9b93efb8c3f. Report an issue: GitHub.