plandex-ai/plandex · error

error fetching model packs: %v

Error message

error fetching model packs: %v

What it means

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.

Source

Thrown at app/server/db/models.go:249

		mp.Coder,
		mp.PlanSummary,
		mp.Builder,
		mp.WholeFileBuilder,
		mp.Namer,
		mp.CommitMsg,
		mp.ExecStatus,
		mp.Architect,
	).Scan(&mp.Id, &mp.CreatedAt)
}

func ListModelPacks(orgId string) ([]*ModelPack, error) {
	var modelPacks []*ModelPack

	query := `SELECT * FROM model_sets WHERE org_id = $1`
	err := Conn.Select(&modelPacks, query, orgId)

	if err != nil {
		return nil, fmt.Errorf("error fetching model packs: %v", err)
	}

	return modelPacks, nil
}

func ListModelPacksForNames(orgId string, names []string) ([]*ModelPack, error) {
	var modelPacks []*ModelPack
	query := `SELECT * FROM model_sets WHERE org_id = $1 AND name = ANY($2)`
	err := Conn.Select(&modelPacks, query, orgId, names)
	return modelPacks, err
}

func DeleteModelPacks(tx *sqlx.Tx, orgId string, ids []string) error {
	if tx == nil {
		return fmt.Errorf("tx is nil")
	}
	_, err := tx.Exec(`DELETE FROM model_sets WHERE org_id = $1 AND id = ANY($2)`, orgId, pq.Array(ids))

View on GitHub (pinned to e2d772072e)

Solutions

  1. Check the wrapped error: 'relation model_sets does not exist' means run migrations; scan errors mean align struct tags with schema
  2. Run pending migrations for model_sets
  3. Compare ModelPack struct db tags against current model_sets columns and fix mismatches
  4. Verify DB connectivity/pool health; add retry for transient connection errors

Example fix

// before
var modelPacks []*ModelPack
err := Conn.Select(&modelPacks, `SELECT * FROM model_sets WHERE org_id = $1`, orgId)
// after
var modelPacks []*ModelPack
err := 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
Defensive patterns

Strategy: try-catch

Validate before calling

// preflight schema check at startup
var n int
if err := Conn.Get(&n, "SELECT count(*) FROM information_schema.tables WHERE table_name = 'model_sets'"); err != nil || n == 0 {
    log.Fatal("model_sets table missing — run migrations")
}

Type guard

func isScanError(err error) bool {
    return err != nil && (strings.Contains(err.Error(), "unsupported Scan") || strings.Contains(err.Error(), "missing destination name"))
}

Try / catch

packs, err := db.ListModelPacks(orgId)
if err != nil {
    if isScanError(err) { log.Printf("ModelPack struct out of sync with model_sets schema: %v", err) }
    http.Error(w, "failed to list model packs", http.StatusInternalServerError)
    return
}

Prevention

When it happens

Trigger: 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.

Common situations: Deploy ran before migrations; model_sets schema changed (column renamed/added with incompatible type) while struct wasn't updated; transient DB restart during request.

Related errors


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