{"record":{"id":"268841966476355f","repo":"plandex-ai/plandex","slug":"error-marshalling-settings","errorCode":null,"errorMessage":"Error marshalling settings","messagePattern":"Error marshalling settings","errorType":"http","errorClass":"http","httpStatus":500,"severity":"error","filePath":"app/server/handlers/settings.go","lineNumber":71,"sourceCode":"\t\t\treturn err\n\t\t}\n\n\t\tsettings = res\n\n\t\treturn nil\n\t})\n\n\tif err != nil {\n\t\tlog.Println(\"Error getting settings: \", err)\n\t\thttp.Error(w, \"Error getting 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 settings: \", err)\n\t\thttp.Error(w, \"Error marshalling settings\", http.StatusInternalServerError)\n\t\treturn\n\t}\n\n\tlog.Println(\"GetSettingsHandler processed successfully\")\n\n\tw.Write(bytes)\n}\n\nfunc UpdateSettingsHandler(w http.ResponseWriter, r *http.Request) {\n\tlog.Println(\"Received request for UpdateSettingsHandler\")\n\n\tauth := Authenticate(w, r, true)\n\tif auth == nil {\n\t\treturn\n\t}\n\n\tvars := mux.Vars(r)\n\tplanId := vars[\"planId\"]","sourceCodeStart":53,"sourceCodeEnd":89,"githubUrl":"https://github.com/plandex-ai/plandex/blob/e2d772072efadbe41d2946d97d79be55532dbab5/app/server/handlers/settings.go#L53-L89","documentation":"After successfully loading settings, GetSettingsHandler serializes them with json.Marshal. If marshaling fails, the handler returns HTTP 500 'Error marshalling settings'. In practice this is rare because the settings structure is JSON-serializable, but it can happen with invalid state such as unsupported types or values injected into the settings object.","triggerScenarios":"json.Marshal(settings) fails: settings contain an unsupported Go type (e.g. func, chan), a cyclic structure, or an invalid value (NaN/Inf float) introduced when settings were loaded or mutated.","commonSituations":"A custom/modified settings struct added an unserializable field; settings data constructed from dynamic/untyped sources contains cycles or bad floats; version mismatch where new fields were never made JSON-safe.","solutions":["Ensure all fields of the settings struct are JSON-serializable types","Remove or handle cycles and non-finite numbers before marshaling","Add a MarshalJSON method for any custom types in the settings schema","Pin server and client versions so the settings schema matches"],"exampleFix":"// before\nbytes, err := json.Marshal(settings)\n// after\nsafe := toSerializableSettings(settings)\nbytes, err := json.Marshal(safe)","handlingStrategy":"fallback","validationCode":null,"typeGuard":null,"tryCatchPattern":"resp, err := client.GetSettings(ctx)\nif err != nil {\n    // 500 'Error marshalling settings': treat as server bug\n    return defaultSettings, nil\n}","preventionTips":["Keep the settings struct JSON-serializable when upgrading versions","Avoid injecting dynamic/untyped data into server settings","Test settings serialization in CI after schema changes"],"tags":["json","go","serialization"],"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-12T22:17:10.623Z"}