plandex-ai/plandex · warning
org not found
Error message
org not found
What it means
GetOrg maps sql.ErrNoRows from the single-row SELECT on orgs to the exact message 'org not found'. This is the deliberate no-result signal: the orgId simply has no row in orgs. Any other query error takes the separate 'error getting org' path.
Source
Thrown at app/server/db/org_helpers.go:76
var orgsFromInvites []*Org
query := fmt.Sprintf("SELECT %s FROM orgs WHERE id = ANY($1)", orgFields)
err = Conn.Select(&orgsFromInvites, query, pq.Array(orgIds))
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
}View on GitHub (pinned to e2d772072e)
Solutions
- Verify the orgId exists: SELECT id FROM orgs WHERE id = '<id>' in the target environment
- Return 404 to the client and have it refresh its org list
- Clean up dangling references (invites, memberships) when orgs are deleted
- Check environment/config — the id may belong to staging while querying prod
Example fix
// before
org, err := db.GetOrg(orgId)
if err != nil { return err }
// after
org, err := db.GetOrg(orgId)
if err != nil {
if err.Error() == "org not found" { http.Error(w, "org not found", http.StatusNotFound); return }
return err
} Defensive patterns
Strategy: try-catch
Validate before calling
var exists bool
err := Conn.Get(&exists, "SELECT EXISTS(SELECT 1 FROM orgs WHERE id = $1)", orgId)
if err == nil && !exists { http.Error(w, "org not found", http.StatusNotFound); return } Type guard
func isOrgNotFound(err error) bool { return err != nil && err.Error() == "org not found" } Try / catch
org, err := db.GetOrg(orgId)
if err != nil {
if isOrgNotFound(err) { http.Error(w, "org not found", http.StatusNotFound); return }
http.Error(w, "internal error", http.StatusInternalServerError)
return
} Prevention
- Map this sentinel to HTTP 404 in every handler that calls GetOrg
- Validate orgId format (UUID) before lookup
- Refresh cached org ids client-side; purge invites/memberships when an org is deleted
- Check you are querying the right environment's database
- Compare with errors.Is/As rather than string matching long-term — prefer a typed sentinel error
When it happens
Trigger: Caller passes an orgId that doesn't exist (typo, wrong environment, deleted org) to GetOrg via handlers like InviteUserHandler or getApiOrg; org row deleted while a user held a stale reference (e.g. from an invite).
Common situations: Client cached an orgId from another environment (staging vs prod); org deleted between listing and detail fetch; user manually editing an org id in an API call; invite pointing at a purged org.
Understand the failure class
Background: Record Not Found Errors: "not found", RecordNotFound, and "was not found" — what they mean and how to fix them — this error's family across 28 libraries.
Related errors
- error getting plan config: %v
- error getting default plan config: %v
- error getting default plan config: %v
- Project not found:
- error adding plan context tokens: %v
AI-assisted analysis of plandex-ai/plandex@e2d772072e (2026-09-05).
Data as JSON: /api/errors/ef67e4a2f22a44cb.
Report an issue: GitHub.