{"record":{"id":"0a94abbd1cde18f9","repo":"plandex-ai/plandex","slug":"error-fetching-model-packs-v","errorCode":null,"errorMessage":"error fetching model packs: %v","messagePattern":"error fetching model packs: (.+?)","errorType":"exception","errorClass":null,"httpStatus":null,"severity":"error","filePath":"app/server/db/models.go","lineNumber":249,"sourceCode":"\t\tmp.Coder,\n\t\tmp.PlanSummary,\n\t\tmp.Builder,\n\t\tmp.WholeFileBuilder,\n\t\tmp.Namer,\n\t\tmp.CommitMsg,\n\t\tmp.ExecStatus,\n\t\tmp.Architect,\n\t).Scan(&mp.Id, &mp.CreatedAt)\n}\n\nfunc ListModelPacks(orgId string) ([]*ModelPack, error) {\n\tvar modelPacks []*ModelPack\n\n\tquery := `SELECT * FROM model_sets WHERE org_id = $1`\n\terr := Conn.Select(&modelPacks, query, orgId)\n\n\tif err != nil {\n\t\treturn nil, fmt.Errorf(\"error fetching model packs: %v\", err)\n\t}\n\n\treturn modelPacks, nil\n}\n\nfunc ListModelPacksForNames(orgId string, names []string) ([]*ModelPack, error) {\n\tvar modelPacks []*ModelPack\n\tquery := `SELECT * FROM model_sets WHERE org_id = $1 AND name = ANY($2)`\n\terr := Conn.Select(&modelPacks, query, orgId, names)\n\treturn modelPacks, err\n}\n\nfunc DeleteModelPacks(tx *sqlx.Tx, orgId string, ids []string) error {\n\tif tx == nil {\n\t\treturn fmt.Errorf(\"tx is nil\")\n\t}\n\t_, err := tx.Exec(`DELETE FROM model_sets WHERE org_id = $1 AND id = ANY($2)`, orgId, pq.Array(ids))\n","sourceCodeStart":231,"sourceCodeEnd":267,"githubUrl":"https://github.com/plandex-ai/plandex/blob/e2d772072efadbe41d2946d97d79be55532dbab5/app/server/db/models.go#L231-L267","documentation":"ListModelPacks wraps a failure of Conn.Select reading all rows from model_sets for an org. This fires on any query error (connection failure, missing table, scan/type mismatch) — not when the org simply has zero model packs (that returns an empty slice). The %v holds the underlying sqlx/pq error.","triggerScenarios":"SELECT against model_sets when the table doesn't exist (migrations missing); DB unreachable; column type in model_sets incompatible with ModelPack struct fields causing a Select scan error.","commonSituations":"Deploy ran before migrations; model_sets schema changed (column renamed/added with incompatible type) while struct wasn't updated; transient DB restart during request.","solutions":["Check the wrapped error: 'relation model_sets does not exist' means run migrations; scan errors mean align struct tags with schema","Run pending migrations for model_sets","Compare ModelPack struct db tags against current model_sets columns and fix mismatches","Verify DB connectivity/pool health; add retry for transient connection errors"],"exampleFix":"// before\nvar modelPacks []*ModelPack\nerr := Conn.Select(&modelPacks, `SELECT * FROM model_sets WHERE org_id = $1`, orgId)\n// after\nvar modelPacks []*ModelPack\nerr := Conn.Select(&modelPacks, `SELECT id, org_id, name, created_at, updated_at FROM model_sets WHERE org_id = $1`, orgId) // explicit columns matching struct db tags","handlingStrategy":"try-catch","validationCode":"// preflight schema check at startup\nvar n int\nif err := Conn.Get(&n, \"SELECT count(*) FROM information_schema.tables WHERE table_name = 'model_sets'\"); err != nil || n == 0 {\n    log.Fatal(\"model_sets table missing — run migrations\")\n}","typeGuard":"func isScanError(err error) bool {\n    return err != nil && (strings.Contains(err.Error(), \"unsupported Scan\") || strings.Contains(err.Error(), \"missing destination name\"))\n}","tryCatchPattern":"packs, err := db.ListModelPacks(orgId)\nif err != nil {\n    if isScanError(err) { log.Printf(\"ModelPack struct out of sync with model_sets schema: %v\", err) }\n    http.Error(w, \"failed to list model packs\", http.StatusInternalServerError)\n    return\n}","preventionTips":["Keep ModelPack db tags aligned with model_sets columns after every schema change","Run migrations in CI and on deploy","Select explicit columns instead of SELECT * to detect drift early","Monitor DB connectivity with health checks","Treat empty result as success (empty slice), not an error"],"tags":["database","postgres","sqlx","scan-error"],"backgroundTag":"sql-scan-failed","analyzedSha":"e2d772072efadbe41d2946d97d79be55532dbab5","analyzedAt":"2026-09-05T20:56:53.631Z","contentChangedAt":"2026-09-05T20:56:53.631Z","schemaVersion":2},"datasetVersion":"2026-09-12T22:17:10.623Z"}