{"record":{"id":"7c51c9271036df82","repo":"plandex-ai/plandex","slug":"error-getting-org-v","errorCode":null,"errorMessage":"error getting org: %v","messagePattern":"error getting org: (.+?)","errorType":"exception","errorClass":null,"httpStatus":null,"severity":"error","filePath":"app/server/db/org_helpers.go","lineNumber":79,"sourceCode":"\t\tif err != nil {\n\t\t\treturn nil, fmt.Errorf(\"error getting orgs from invites: %v\", err)\n\t\t}\n\t\torgs = append(orgs, orgsFromInvites...)\n\t}\n\n\treturn orgs, nil\n}\nfunc GetOrg(orgId string) (*Org, error) {\n\tvar org Org\n\tquery := fmt.Sprintf(\"SELECT %s FROM orgs WHERE id = $1\", orgFields)\n\terr := Conn.Get(&org, query, orgId)\n\n\tif err != nil {\n\t\tif err == sql.ErrNoRows {\n\t\t\treturn nil, fmt.Errorf(\"org not found\")\n\t\t}\n\n\t\treturn nil, fmt.Errorf(\"error getting org: %v\", err)\n\t}\n\n\treturn &org, nil\n}\n\nfunc ValidateOrgMembership(userId string, orgId string) (bool, error) {\n\tvar count int\n\terr := Conn.QueryRow(\"SELECT COUNT(*) FROM orgs_users WHERE user_id = $1 AND org_id = $2\", userId, orgId).Scan(&count)\n\n\tif err != nil {\n\t\treturn false, fmt.Errorf(\"error validating org membership: %v\", err)\n\t}\n\n\treturn count > 0, nil\n}\n\nfunc CreateOrg(req *shared.CreateOrgRequest, userId string, domain *string, tx *sqlx.Tx) (*Org, error) {\n\torg := &Org{","sourceCodeStart":61,"sourceCodeEnd":97,"githubUrl":"https://github.com/plandex-ai/plandex/blob/e2d772072efadbe41d2946d97d79be55532dbab5/app/server/db/org_helpers.go#L61-L97","documentation":"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.","triggerScenarios":"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).","commonSituations":"Schema drift after a migration renamed an orgs column; database failover mid-request; new environment without migrations applied.","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"],"exampleFix":"// before\nreturn nil, fmt.Errorf(\"error getting org: %v\", err)\n// after\nvar pgErr *pgconn.PgError\nif errors.As(err, &pgErr) && pgErr.Code == \"42P01\" { // undefined_table\n    return nil, fmt.Errorf(\"error getting org: migrations missing: %w\", err)\n}\nreturn nil, fmt.Errorf(\"error getting org: %w\", err)","handlingStrategy":"try-catch","validationCode":"// readiness check: orgs reachable\nvar one int\nif err := Conn.Get(&one, \"SELECT 1\"); err != nil { log.Printf(\"db unreachable: %v\", err) }","typeGuard":"func isOrgQueryError(err error) bool { return err != nil && strings.HasPrefix(err.Error(), \"error getting org:\") }","tryCatchPattern":"org, err := db.GetOrg(orgId)\nif err != nil {\n    var pgErr *pgconn.PgError\n    switch {\n    case errors.As(err, &pgErr) && pgErr.Code == \"42703\":\n        log.Printf(\"orgs schema drift: %s\", pgErr.Message)\n    case isOrgQueryError(err):\n        // transient DB issue — retry or return 503\n    }\n    return err\n}","preventionTips":["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"],"tags":["database","postgres","sqlx","error-wrapping"],"backgroundTag":"sql-query-failed","analyzedSha":"e2d772072efadbe41d2946d97d79be55532dbab5","analyzedAt":"2026-09-05T20:56:53.631Z","contentChangedAt":"2026-09-05T20:56:53.631Z","schemaVersion":2},"datasetVersion":"2026-09-14T00:17:10.932Z"}