{"record":{"id":"1644e9ea8a5d7198","repo":"plandex-ai/plandex","slug":"error-marshalling-default-settings","errorCode":null,"errorMessage":"Error marshalling default settings","messagePattern":"Error marshalling default settings","errorType":"http","errorClass":null,"httpStatus":500,"severity":"error","filePath":"app/server/handlers/settings.go","lineNumber":245,"sourceCode":"\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\")\n\n\tauth := Authenticate(w, r, true)\n\n\tif auth == nil {\n\t\treturn\n\t}\n\n\tvar req shared.UpdateSettingsRequest","sourceCodeStart":227,"sourceCodeEnd":263,"githubUrl":"https://github.com/plandex-ai/plandex/blob/e2d772072efadbe41d2946d97d79be55532dbab5/app/server/handlers/settings.go#L227-L263","documentation":"After loading settings, GetDefaultSettingsHandler serializes them with json.Marshal. If marshaling fails (practically only when PlanSettings contains an unsupported value such as a bad channel, func, or a custom MarshalJSON that errors), the handler logs and returns 500 'Error marshalling default settings'.","triggerScenarios":"GET default settings succeeds at the DB layer but json.Marshal(settings) returns an error, typically from an invalid value inside the PlanSettings struct or a custom MarshalJSON implementation failing.","commonSituations":"A newly added field in PlanSettings has a type json can't encode; a custom marshaller panics/errs on nil nested pointers after a schema change; version mismatch between server and shared lib structs.","solutions":["Check the server log for 'Error marshalling default settings:' to identify the offending field","Audit PlanSettings for unsupported field types (chan, func, cyclic pointers)","Ensure server and plandex-shared versions are in sync","Add json marshal tests over a freshly loaded PlanSettings fixture","Redeploy after fixing the struct"],"exampleFix":null,"handlingStrategy":"try-catch","validationCode":null,"typeGuard":"func marshalable(v any) (ok bool) {\n    defer func() { if r := recover(); r != nil { ok = false } }()\n    _, err := json.Marshal(v)\n    return err == nil\n}","tryCatchPattern":"const res = await api.getDefaultSettings();\ntry { JSON.parse(res.body); } catch { // treat as server serialization bug\n  reportBug('unparseable settings payload'); fallbackToCachedSettings();\n}","preventionTips":["Add round-trip (marshal/unmarshal) tests for PlanSettings fixtures","Keep server and shared-lib versions in lockstep","Avoid unsupported field types (chan, func) in shared structs","Validate settings payloads with CI before release"],"tags":["json","serialization","http-500"],"backgroundTag":"json-marshal-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"}