plandex-ai/plandex · error

err.Error()

Error message

err.Error()

What it means

GetCustomProviderHandler calls db.GetCustomProvider(auth.OrgId, providerId); on error it writes err.Error() verbatim to the client with HTTP 500. The message the client sees is literally the raw database/lookup error string, meaning the custom provider fetch failed at the data layer for that org+providerId.

Source

Thrown at app/server/handlers/models.go:417

		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")
}

func GetCustomProviderHandler(w http.ResponseWriter, r *http.Request) {
	auth := Authenticate(w, r, true)
	if auth == nil {
		return
	}

	id := mux.Vars(r)["providerId"]

	res, err := db.GetCustomProvider(auth.OrgId, id)
	if err != nil {
		http.Error(w, err.Error(), http.StatusInternalServerError)
		return
	}

	err = json.NewEncoder(w).Encode(res.ToApi())
	if err != nil {
		log.Printf("Error encoding custom provider: %v\n", err)
		http.Error(w, fmt.Sprintf("Error encoding custom provider: %v", err), http.StatusInternalServerError)
		return
	}

	log.Println("Successfully fetched custom provider")
}

func ListCustomProvidersHandler(w http.ResponseWriter, r *http.Request) {
	auth := Authenticate(w, r, true)
	if auth == nil {
		return
	}

View on GitHub (pinned to e2d772072e)

Solutions

  1. Inspect the raw error string in the 500 response — it names the underlying DB failure.
  2. Verify the providerId exists for the authenticated org (list providers first).
  3. Check DB connectivity and that migrations for the custom providers table are applied.
  4. Note the handler leaks err.Error() to clients and returns 500 for what may be 'not found' — harden it to map missing rows to 404.

Example fix

// before
res, err := db.GetCustomProvider(auth.OrgId, id)
if err != nil {
    http.Error(w, err.Error(), http.StatusInternalServerError)
}
// after
res, err := db.GetCustomProvider(auth.OrgId, id)
if err != nil {
    if errors.Is(err, sql.ErrNoRows) {
        http.Error(w, "Custom provider not found", http.StatusNotFound)
    } else {
        log.Printf("Error fetching custom provider: %v\n", err)
        http.Error(w, "Failed to fetch custom provider", http.StatusInternalServerError)
    }
    return
}
Defensive patterns

Strategy: validation

Validate before calling

// Caller-side: confirm the providerId is non-empty and belongs to the org before calling
if providerId == "" {
    return errors.New("providerId is required")
}
providers, _ := listCustomProviders(orgId)
if !containsProvider(providers, providerId) {
    return fmt.Errorf("provider %s not found for org", providerId)
}

Try / catch

res, err := db.GetCustomProvider(orgId, providerId)
if err != nil {
    if errors.Is(err, sql.ErrNoRows) {
        http.Error(w, "Custom provider not found", http.StatusNotFound)
        return
    }
    log.Printf("Error fetching custom provider: %v", err)
    http.Error(w, "Failed to fetch custom provider", http.StatusInternalServerError)
    return
}

Prevention

When it happens

Trigger: GET custom provider with a providerId whose DB lookup fails: provider row missing in a corrupted state, DB connection error, or query/schema error (an absent provider normally returns nil, res==nil, not an error here).

Common situations: Requesting a providerId that was deleted or belongs to another org while the DB layer surfaces it as an error; DB outage; unapplied migrations for the providers table.

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/0cfe76b4158bc505. Report an issue: GitHub.