plandex-ai/plandex · error
Failed to fetch custom models:
Error message
Failed to fetch custom models:
What it means
ListCustomModelsHandler calls db.ListCustomModels(auth.OrgId) to enumerate an org's custom models; if the DB layer returns an error the handler logs it and responds 500 'Failed to fetch custom models: <err>'. This indicates the backing database read for that org failed, not a client input problem.
Source
Thrown at app/server/handlers/models.go:388
log.Println("Successfully fetched custom model")
}
func ListCustomModelsHandler(w http.ResponseWriter, r *http.Request) {
log.Println("Received request for ListCustomModelsHandler")
auth := Authenticate(w, r, true)
if auth == nil {
return
}
if !requireMinClientVersion(w, r, CustomModelsMinClientVersion) {
return
}
models, err := db.ListCustomModels(auth.OrgId)
if err != nil {
log.Printf("Error fetching custom models: %v\n", err)
http.Error(w, "Failed to fetch custom models: "+err.Error(), http.StatusInternalServerError)
return
}
var apiList []*shared.CustomModel
for _, m := range models {
apiList = append(apiList, m.ToApi())
}
err = json.NewEncoder(w).Encode(apiList)
if err != nil {
log.Printf("Error encoding custom models: %v\n", err)
http.Error(w, fmt.Sprintf("Error encoding custom models: %v", err), http.StatusInternalServerError)
return
}
log.Println("Successfully fetched custom models")
}
View on GitHub (pinned to e2d772072e)
Solutions
- Read the logged 'Error fetching custom models: ...' detail — it contains the underlying DB error.
- Verify DB connectivity from the server (ping, connection string/env config like DB host/port/user).
- Confirm migrations ran and the custom models table/schema matches what db.ListCustomModels expects.
- Check connection pool limits and DB logs for max_connections or timeout errors under load.
Example fix
// before
http.Error(w, "Failed to fetch custom models: "+err.Error(), http.StatusInternalServerError)
// after
if errors.Is(err, sql.ErrNoRows) || strings.Contains(err.Error(), "does not exist") {
http.Error(w, "custom models schema missing; run migrations", http.StatusInternalServerError)
} else {
log.Printf("Error fetching custom models: %v\n", err)
http.Error(w, "Failed to fetch custom models", http.StatusInternalServerError) // avoid leaking DB details
} Defensive patterns
Strategy: retry
Validate before calling
// Caller-side precheck: confirm the service is reachable and authenticated before listing
resp, err := http.Get(baseURL + "/healthz")
if err != nil || resp.StatusCode != 200 {
return fmt.Errorf("models service unavailable: %v", err)
} Try / catch
models, err := db.ListCustomModels(orgId)
if err != nil {
if isTransient(err) { // net.Error timeout, driver conn errors
// retry once with backoff
}
log.Printf("Error fetching custom models: %v", err)
http.Error(w, "Failed to fetch custom models", http.StatusInternalServerError)
return
} Prevention
- Ensure migrations run on deploy so the custom models table always exists
- Monitor DB health and pool saturation; alert on connection errors
- Validate DB connection env vars in every environment before startup
- Wrap transient DB errors with retry/backoff instead of failing the request immediately
When it happens
Trigger: Calling GET /custom models when db.ListCustomModels fails: database unreachable, query error, connection pool exhaustion, schema mismatch, or missing table.
Common situations: Database container down or restarted; migration not applied so the custom_models table/columns are missing; connection string/env var misconfigured in a new environment; pool exhausted under load.
Understand the failure class
Background: Database query failed: Internal Server Error 500s wrapping SQL, Prisma, and connection failures — what to check first — this error's family across 16 libraries.
Related errors
AI-assisted analysis of plandex-ai/plandex@e2d772072e (2026-09-05).
Data as JSON: /api/errors/5f01a840a96e9484.
Report an issue: GitHub.