plandex-ai/plandex · error

error listing org roles: %v

Error message

error listing org roles: %v

What it means

ListOrgRoles wraps a failure of `SELECT * FROM org_roles WHERE org_id IS NULL OR org_id = $1` (sqlx Conn.Select) with this message. It is a query/scan/connection failure surfaced to ListOrgRolesHandler, not an empty-result condition — an empty role set returns (nil, nil).

Source

Thrown at app/server/db/org_helpers.go:214

	if tx == nil {
		_, err = Conn.Exec(query, orgId, userId, orgRoleId)
	} else {
		_, err = tx.Exec(query, orgId, userId, orgRoleId)
	}

	if err != nil {
		return fmt.Errorf("error adding org member: %v", err)
	}

	return nil
}

func ListOrgRoles(orgId string) ([]*OrgRole, error) {
	var orgRoles []*OrgRole
	err := Conn.Select(&orgRoles, "SELECT * FROM org_roles WHERE org_id IS NULL OR org_id = $1", orgId)

	if err != nil {
		return nil, fmt.Errorf("error listing org roles: %v", err)
	}

	return orgRoles, nil
}

func AddToOrgForDomain(userId, domain string, tx *sqlx.Tx) (string, error) {
	org, err := GetOrgForDomain(domain)

	if err != nil {
		return "", fmt.Errorf("error getting org for domain: %v", err)
	}

	orgOwnerRoleId, err := GetOrgOwnerRoleId()

	if err != nil {
		return "", fmt.Errorf("error getting org owner role id: %v", err)
	}

View on GitHub (pinned to e2d772072e)

Solutions

  1. Read the wrapped cause: 'relation "org_roles" does not exist' means run database migrations
  2. Confirm the server is pointed at the intended DATABASE_URL environment (dev vs prod)
  3. Check DB connectivity/pool health and retry the request
  4. Verify the OrgRole struct fields match the org_roles columns (sqlx scan errors)

Example fix

// before
roles, err := ListOrgRoles(orgId)
// after: surface a clear handler error and check migrations first
if err != nil {
    log.Printf("ListOrgRoles failed: %v", err) // inspect cause
    http.Error(w, "failed to list org roles; ensure migrations are applied", http.StatusInternalServerError)
    return
}
Defensive patterns

Strategy: retry

Validate before calling

// verify DB reachable and table present before querying
var one int
if err := Conn.Get(&one, "SELECT 1 FROM org_roles LIMIT 1"); err != nil {
    log.Printf("org_roles unavailable (migrations applied?): %v", err)
}

Try / catch

roles, err := ListOrgRoles(orgId)
if err != nil {
    log.Printf("ListOrgRoles: %v", err) // preserve cause for triage
    http.Error(w, "unable to list roles", http.StatusInternalServerError)
    return
}

Prevention

When it happens

Trigger: ListOrgRoles is called with any orgId while the org_roles table is missing, the query is malformed for the live schema (e.g. migration not applied), the DB connection is broken, or a column cannot be scanned into *OrgRole.

Common situations: Running the server against a database with pending migrations; connecting to the wrong database/environment; connection pool exhausted after a Postgres restart; schema drift after an upgrade added/renamed columns.

Related errors


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