{"record":{"id":"1dc618ced9568b8e","repo":"plandex-ai/plandex","slug":"error-encoding-custom-providers-v","errorCode":null,"errorMessage":"Error encoding custom providers: %v","messagePattern":"Error encoding custom providers: (.+?)","errorType":"http","errorClass":null,"httpStatus":500,"severity":"error","filePath":"app/server/handlers/models.go","lineNumber":456,"sourceCode":"\t\thttp.Error(w, \"Custom model providers are not supported on Plandex Cloud\", http.StatusBadRequest)\n\t\treturn\n\t}\n\n\tlist, err := db.ListCustomProviders(auth.OrgId)\n\tif err != nil {\n\t\thttp.Error(w, err.Error(), http.StatusInternalServerError)\n\t\treturn\n\t}\n\n\tvar apiList []*shared.CustomProvider\n\tfor _, p := range list {\n\t\tapiList = append(apiList, p.ToApi())\n\t}\n\n\terr = json.NewEncoder(w).Encode(apiList)\n\tif err != nil {\n\t\tlog.Printf(\"Error encoding custom providers: %v\\n\", err)\n\t\thttp.Error(w, fmt.Sprintf(\"Error encoding custom providers: %v\", err), http.StatusInternalServerError)\n\t\treturn\n\t}\n\n\tlog.Println(\"Successfully fetched custom providers\")\n}\n\nfunc CreateModelPackHandler(w http.ResponseWriter, r *http.Request) {\n\tlog.Println(\"Received request for CreateModelPackHandler\")\n\n\tauth := Authenticate(w, r, true)\n\tif auth == nil {\n\t\treturn\n\t}\n\n\tif !requireMinClientVersion(w, r, CustomModelsMinClientVersion) {\n\t\treturn\n\t}\n","sourceCodeStart":438,"sourceCodeEnd":474,"githubUrl":"https://github.com/plandex-ai/plandex/blob/e2d772072efadbe41d2946d97d79be55532dbab5/app/server/handlers/models.go#L438-L474","documentation":"After listing providers and converting them with ToApi(), the handler encodes the response with json.NewEncoder(w).Encode(apiList). If encoding fails (response writer broken, encoding error), it logs 'Error encoding custom providers' and returns HTTP 500.","triggerScenarios":"json.NewEncoder(w).Encode(apiList) returns an error — typically the client disconnected before the body was written, the ResponseWriter is in a bad state, or an apiList value fails to serialize.","commonSituations":"Clients aborting the request mid-response (network flake, short HTTP timeout, load-balancer health checks closing connections); large provider lists exceeding client timeouts.","solutions":["Retry the request; this is usually a transient client/connection failure.","Check the server log for the '%v' detail to confirm the actual encoding error.","Ensure the client keeps the connection open until the response completes (raise timeout).","Verify shared.CustomProvider.ToApi() output contains only JSON-serializable fields."],"exampleFix":"// before: double-writes status if headers already sent\nerr = json.NewEncoder(w).Encode(apiList)\nif err != nil {\n\thttp.Error(w, fmt.Sprintf(\"Error encoding custom providers: %v\", err), http.StatusInternalServerError)\n}\n// after: guard with content type and log-only when headers sent\nw.Header().Set(\"Content-Type\", \"application/json\")\nif err := json.NewEncoder(w).Encode(apiList); err != nil {\n\tlog.Printf(\"Error encoding custom providers: %v\\n\", err)\n}","handlingStrategy":"retry","validationCode":null,"typeGuard":null,"tryCatchPattern":"resp, err := client.Get(url)\nif err != nil { return err }\nif resp.StatusCode == 500 {\n\t// often a mid-response disconnect; safe to retry with backoff\n\treturn retryWithBackoff(3, 500*time.Millisecond)\n}\njson.NewDecoder(resp.Body).Decode(&apiList)","preventionTips":["Use client HTTP timeouts long enough to receive full responses.","Avoid cancelling requests mid-stream (no fire-and-forget contexts).","Check server logs for the 'Error encoding custom providers' detail when it recurs."],"tags":["http-500","json","encoding"],"backgroundTag":"json-encoding-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"}