plandex-ai/plandex · error
error getting org: %v
Error message
error getting org: %v
What it means
GetOrg wraps any non-ErrNoRows failure of the orgs lookup with this message. Unlike 'org not found', this means the query itself failed: DB connectivity, missing table, bad column in orgFields, or a scan error on the Org struct.
Source
Thrown at app/server/db/org_helpers.go:79
if err != nil {
return nil, fmt.Errorf("error getting orgs from invites: %v", err)
}
orgs = append(orgs, orgsFromInvites...)
}
return orgs, nil
}
func GetOrg(orgId string) (*Org, error) {
var org Org
query := fmt.Sprintf("SELECT %s FROM orgs WHERE id = $1", orgFields)
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{View on GitHub (pinned to e2d772072e)
Solutions
- Inspect the wrapped error: 'column does not exist' → fix orgFields; 'relation orgs does not exist' → migrate; scan errors → align Org db tags
- Run pending migrations
- Keep orgFields and the Org struct in sync with the orgs schema
- Add transient-error retry around DB reads
Example fix
// before
return nil, fmt.Errorf("error getting org: %v", err)
// after
var pgErr *pgconn.PgError
if errors.As(err, &pgErr) && pgErr.Code == "42P01" { // undefined_table
return nil, fmt.Errorf("error getting org: migrations missing: %w", err)
}
return nil, fmt.Errorf("error getting org: %w", err) Defensive patterns
Strategy: try-catch
Validate before calling
// readiness check: orgs reachable
var one int
if err := Conn.Get(&one, "SELECT 1"); err != nil { log.Printf("db unreachable: %v", err) } Type guard
func isOrgQueryError(err error) bool { return err != nil && strings.HasPrefix(err.Error(), "error getting org:") } Try / catch
org, err := db.GetOrg(orgId)
if err != nil {
var pgErr *pgconn.PgError
switch {
case errors.As(err, &pgErr) && pgErr.Code == "42703":
log.Printf("orgs schema drift: %s", pgErr.Message)
case isOrgQueryError(err):
// transient DB issue — retry or return 503
}
return err
} Prevention
- Distinguish this from 'org not found' — it needs a 5xx, not a 404
- Keep orgFields and Org struct aligned with the orgs schema
- Run migrations before deploy
- Add transient-error retry (connection resets, failover) around org reads
- Wrap with %w so errors.As can extract the pq error code
When it happens
Trigger: DB unreachable or pool exhausted; orgs table missing (stale migrations); orgFields references a dropped/renamed column; Org struct fields incompatible with returned columns (Conn.Get scan error).
Common situations: Schema drift after a migration renamed an orgs column; database failover mid-request; new environment without migrations applied.
Understand the failure class
Background: "query failed", "%w: SQL error" — wrapped database query errors in Go libraries explained — this error's family across 3 libraries.
Related errors
- error getting invites for user: %v
- error deleting custom models: %v
- error deleting custom providers: %v
- error fetching model packs: %v
- error deleting model pack: %v
AI-assisted analysis of plandex-ai/plandex@e2d772072e (2026-09-05).
Data as JSON: /api/errors/7c51c9271036df82.
Report an issue: GitHub.