{"record":{"id":"8b084e241d62be13","repo":"plandex-ai/plandex","slug":"error-getting-default-settings","errorCode":null,"errorMessage":"Error getting default settings","messagePattern":"Error getting default settings","errorType":"http","errorClass":"http","httpStatus":500,"severity":"error","filePath":"app/server/handlers/settings.go","lineNumber":237,"sourceCode":"\tw.Write(bytes)\n\n\tlog.Println(\"UpdateSettingsHandler processed successfully\")\n\n}\n\nfunc GetDefaultSettingsHandler(w http.ResponseWriter, r *http.Request) {\n\tlog.Println(\"Received request for GetDefaultSettingsHandler\")\n\n\tauth := Authenticate(w, r, true)\n\tif auth == nil {\n\t\treturn\n\t}\n\n\tsettings, err := db.GetOrgDefaultSettings(auth.OrgId)\n\n\tif err != nil {\n\t\tlog.Println(\"Error getting default settings: \", err)\n\t\thttp.Error(w, \"Error getting default settings\", http.StatusInternalServerError)\n\t\treturn\n\t}\n\n\tbytes, err := json.Marshal(settings)\n\n\tif err != nil {\n\t\tlog.Println(\"Error marshalling default settings: \", err)\n\t\thttp.Error(w, \"Error marshalling default settings\", http.StatusInternalServerError)\n\t\treturn\n\t}\n\n\tw.Write(bytes)\n\n\tlog.Println(\"GetDefaultSettingsHandler processed successfully\")\n}\n\nfunc UpdateDefaultSettingsHandler(w http.ResponseWriter, r *http.Request) {\n\tlog.Println(\"Received request for UpdateDefaultSettingsHandler\")","sourceCodeStart":219,"sourceCodeEnd":255,"githubUrl":"https://github.com/plandex-ai/plandex/blob/e2d772072efadbe41d2946d97d79be55532dbab5/app/server/handlers/settings.go#L219-L255","documentation":"GetDefaultSettingsHandler fetches the org's default plan settings via db.GetOrgDefaultSettings. When that DB query returns any error (connection failure, missing row scan error, context cancellation), the handler logs it and responds 500 with a generic 'Error getting default settings' body, deliberately hiding the underlying DB error from the client.","triggerScenarios":"GET the org default settings endpoint when the database is unreachable, the org row/default-settings row is missing or corrupt, the SQL scan fails due to schema drift, or the request context is cancelled mid-query.","commonSituations":"Postgres down or restarted during a deploy; org deleted while a stale auth token still references its ID; migrations not applied so the settings table/columns don't match the struct; connection pool exhausted under load.","solutions":["Check the server log for the 'Error getting default settings:' line to see the underlying DB error","Verify the database is reachable and migrations are up to date","Confirm the org ID in the auth token still exists in the orgs table","If scans fail after an upgrade, redeploy server and shared lib versions together","Retry the request once the DB is healthy"],"exampleFix":"// before\nsettings, err := db.GetOrgDefaultSettings(auth.OrgId)\nif err != nil {\n    http.Error(w, \"Error getting default settings\", http.StatusInternalServerError)\n    return\n}\n// after\nsettings, err := db.GetOrgDefaultSettings(auth.OrgId)\nif err != nil {\n    if errors.Is(err, sql.ErrNoRows) {\n        http.Error(w, \"No default settings found for org\", http.StatusNotFound)\n        return\n    }\n    log.Println(\"Error getting default settings: \", err)\n    http.Error(w, \"Error getting default settings\", http.StatusInternalServerError)\n    return\n}","handlingStrategy":"retry","validationCode":"// client-side pre-check\nif (!orgId) throw new Error('orgId is required before fetching default settings');\nconst res = await fetch(`${base}/org/default-settings`, { headers: authHeaders });\nif (!res.ok && res.status >= 500) scheduleRetry();","typeGuard":"func isRetryableDBError(err error) bool {\n    var netErr net.Error\n    return errors.As(err, &netErr) || errors.Is(err, sql.ErrConnDone) || errors.Is(err, driver.ErrBadConn)\n}","tryCatchPattern":"try {\n  const res = await api.getDefaultSettings();\n} catch (e) {\n  if (e.status === 500) { logServerIssue(e); await waitForDbHealthy(); retry(); }\n  else throw e;\n}","preventionTips":["Keep migrations applied before deploying server updates","Monitor DB health/uptime and alert on outages","Retry idempotent GETs on 5xx with backoff","Check server logs for the underlying DB error on any 500"],"tags":["database","http-500","settings"],"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-12T22:17:10.623Z"}