{"record":{"id":"0cfe76b4158bc505","repo":"plandex-ai/plandex","slug":"err-error-0cfe76","errorCode":null,"errorMessage":"err.Error()","messagePattern":"err\\.Error\\(\\)","errorType":"http","errorClass":null,"httpStatus":500,"severity":"error","filePath":"app/server/handlers/models.go","lineNumber":417,"sourceCode":"\t\tlog.Printf(\"Error encoding custom models: %v\\n\", err)\n\t\thttp.Error(w, fmt.Sprintf(\"Error encoding custom models: %v\", err), http.StatusInternalServerError)\n\t\treturn\n\t}\n\n\tlog.Println(\"Successfully fetched custom models\")\n}\n\nfunc GetCustomProviderHandler(w http.ResponseWriter, r *http.Request) {\n\tauth := Authenticate(w, r, true)\n\tif auth == nil {\n\t\treturn\n\t}\n\n\tid := mux.Vars(r)[\"providerId\"]\n\n\tres, err := db.GetCustomProvider(auth.OrgId, id)\n\tif err != nil {\n\t\thttp.Error(w, err.Error(), http.StatusInternalServerError)\n\t\treturn\n\t}\n\n\terr = json.NewEncoder(w).Encode(res.ToApi())\n\tif err != nil {\n\t\tlog.Printf(\"Error encoding custom provider: %v\\n\", err)\n\t\thttp.Error(w, fmt.Sprintf(\"Error encoding custom provider: %v\", err), http.StatusInternalServerError)\n\t\treturn\n\t}\n\n\tlog.Println(\"Successfully fetched custom provider\")\n}\n\nfunc ListCustomProvidersHandler(w http.ResponseWriter, r *http.Request) {\n\tauth := Authenticate(w, r, true)\n\tif auth == nil {\n\t\treturn\n\t}","sourceCodeStart":399,"sourceCodeEnd":435,"githubUrl":"https://github.com/plandex-ai/plandex/blob/e2d772072efadbe41d2946d97d79be55532dbab5/app/server/handlers/models.go#L399-L435","documentation":"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.","triggerScenarios":"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).","commonSituations":"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.","solutions":["Inspect the raw error string in the 500 response — it names the underlying DB failure.","Verify the providerId exists for the authenticated org (list providers first).","Check DB connectivity and that migrations for the custom providers table are applied.","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."],"exampleFix":"// before\nres, err := db.GetCustomProvider(auth.OrgId, id)\nif err != nil {\n    http.Error(w, err.Error(), http.StatusInternalServerError)\n}\n// after\nres, err := db.GetCustomProvider(auth.OrgId, id)\nif err != nil {\n    if errors.Is(err, sql.ErrNoRows) {\n        http.Error(w, \"Custom provider not found\", http.StatusNotFound)\n    } else {\n        log.Printf(\"Error fetching custom provider: %v\\n\", err)\n        http.Error(w, \"Failed to fetch custom provider\", http.StatusInternalServerError)\n    }\n    return\n}","handlingStrategy":"validation","validationCode":"// Caller-side: confirm the providerId is non-empty and belongs to the org before calling\nif providerId == \"\" {\n    return errors.New(\"providerId is required\")\n}\nproviders, _ := listCustomProviders(orgId)\nif !containsProvider(providers, providerId) {\n    return fmt.Errorf(\"provider %s not found for org\", providerId)\n}","typeGuard":null,"tryCatchPattern":"res, err := db.GetCustomProvider(orgId, providerId)\nif err != nil {\n    if errors.Is(err, sql.ErrNoRows) {\n        http.Error(w, \"Custom provider not found\", http.StatusNotFound)\n        return\n    }\n    log.Printf(\"Error fetching custom provider: %v\", err)\n    http.Error(w, \"Failed to fetch custom provider\", http.StatusInternalServerError)\n    return\n}","preventionTips":["Never return raw err.Error() to clients — log it server-side and return a generic message","Map not-found DB errors to 404 rather than 500","Validate providerId (non-empty, expected format) before the DB call","Keep DB migrations in sync so the providers schema always matches the query"],"tags":["go","database","http","error-leak"],"backgroundTag":"database-query-failed","analyzedSha":"e2d772072efadbe41d2946d97d79be55532dbab5","analyzedAt":"2026-09-05T20:56:53.631Z","contentChangedAt":"2026-09-05T20:56:53.631Z","schemaVersion":2},"datasetVersion":"2026-09-14T00:17:10.932Z"}