plandex-ai/plandex · error
error validating org membership: %v
Error message
error validating org membership: %v
What it means
ValidateOrgMembership wraps any error from the COUNT(*) query against orgs_users into 'error validating org membership: %v'. This means the membership check could not be performed at all — it is a database-layer failure (connectivity, bad SQL, scan error), not a 'user is not a member' result. The boolean false return paired with the error must not be interpreted as a definitive denial.
Source
Thrown at app/server/db/org_helpers.go:90
err := Conn.Get(&org, query, orgId)
if err != nil {
if err == sql.ErrNoRows {
return nil, fmt.Errorf("org not found")
}
return nil, fmt.Errorf("error getting org: %v", err)
}
return &org, nil
}
func ValidateOrgMembership(userId string, orgId string) (bool, error) {
var count int
err := Conn.QueryRow("SELECT COUNT(*) FROM orgs_users WHERE user_id = $1 AND org_id = $2", userId, orgId).Scan(&count)
if err != nil {
return false, fmt.Errorf("error validating org membership: %v", err)
}
return count > 0, nil
}
func CreateOrg(req *shared.CreateOrgRequest, userId string, domain *string, tx *sqlx.Tx) (*Org, error) {
org := &Org{
Name: req.Name,
Domain: domain,
AutoAddDomainUsers: req.AutoAddDomainUsers,
OwnerId: userId,
}
err := tx.QueryRow("INSERT INTO orgs (name, domain, auto_add_domain_users, owner_id, is_trial) VALUES ($1, $2, $3, $4, false) RETURNING id", req.Name, domain, req.AutoAddDomainUsers, userId).Scan(&org.Id)
if err != nil {
if IsNonUniqueErr(err) {
// Handle the uniqueness constraint violationView on GitHub (pinned to e2d772072e)
Solutions
- Check the wrapped %v error for a pq/lib/pq connection failure and verify the Postgres instance is reachable from the server
- Run schema migrations to ensure the orgs_users table and columns exist
- Verify DATABASE_URL / Conn initialization and connection-pool limits
- Retry the request once the database is healthy; the error is transient in most cases
Example fix
// before
ok, err := db.ValidateOrgMembership(userId, orgId)
if err != nil { /* treat as not-member */ }
// after
ok, err := db.ValidateOrgMembership(userId, orgId)
if err != nil {
log.Printf("membership check failed (db error): %v", err)
http.Error(w, "internal error", http.StatusInternalServerError)
return
} Defensive patterns
Strategy: try-catch
Validate before calling
// Go has no pre-call check; validate inputs are non-empty UUIDs before calling
if userId == "" || orgId == "" { return false, errors.New("userId and orgId required") } Type guard
// Distinguish db-layer failure from definitive 'not a member'
func isDBErr(err error) bool { return err != nil && !strings.Contains(err.Error(), "no rows") } Try / catch
ok, err := db.ValidateOrgMembership(userId, orgId)
if err != nil {
log.Printf("org membership validation failed: %v", err)
return fmt.Errorf("membership check unavailable, try again")
}
if !ok { /* definitively not a member */ } Prevention
- Never treat the error return as 'not a member' — only a nil error with false means that
- Monitor Postgres health/alerts; this error usually appears during outages
- Keep migrations applied so orgs_users always exists
- Set sane connection-pool limits and retries on the DB handle
When it happens
Trigger: Any call to ValidateOrgMembership when the Postgres query fails: DB connection dropped/pool exhausted, orgs_users table missing, or Conn.QueryRow(...).Scan failing on a row error. Called from execAuthenticate, InviteUserHandler and DeleteOrgUserHandler.
Common situations: Postgres is down or restarting during deploy; connection pool saturated under load; schema migrations not applied so orgs_users does not exist; using the function with a stale Conn handle after a connection reset.
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 adding convo tokens: %v
- error checking settings: %v
- error creating postgres driver: %v
- error creating org: %v
- error adding org membership: %v
AI-assisted analysis of plandex-ai/plandex@e2d772072e (2026-09-05).
Data as JSON: /api/errors/f090ad25e9e5454c.
Report an issue: GitHub.