{"record":{"id":"3baf6e56374258fe","repo":"plandex-ai/plandex","slug":"error-marshalling-branches-3baf6e","errorCode":null,"errorMessage":"Error marshalling branches: ","messagePattern":"Error marshalling branches: ","errorType":"http","errorClass":null,"httpStatus":500,"severity":"error","filePath":"app/server/handlers/plans_crud.go","lineNumber":651,"sourceCode":"\tvar branches []db.Branch\n\terr = db.Conn.Select(&branches, query, queryArgs...)\n\n\tif err != nil {\n\t\tlog.Printf(\"Error getting branches: %v\\n\", err)\n\t\thttp.Error(w, \"Error getting branches: \"+err.Error(), http.StatusInternalServerError)\n\t\treturn\n\t}\n\n\tres := map[string]*shared.Branch{}\n\tfor _, branch := range branches {\n\t\tres[branch.PlanId] = branch.ToApi()\n\t}\n\n\tbytes, err := json.Marshal(res)\n\n\tif err != nil {\n\t\tlog.Printf(\"Error marshalling branches: %v\\n\", err)\n\t\thttp.Error(w, \"Error marshalling branches: \"+err.Error(), http.StatusInternalServerError)\n\t\treturn\n\t}\n\n\tlog.Println(\"Successfully processed GetCurrentBranchByPlanIdHandler request\")\n\n\tw.Write(bytes)\n}\n","sourceCodeStart":633,"sourceCodeEnd":659,"githubUrl":"https://github.com/plandex-ai/plandex/blob/e2d772072efadbe41d2946d97d79be55532dbab5/app/server/handlers/plans_crud.go#L633-L659","documentation":"A 500 returned when json.Marshal fails on the map[string]*shared.Branch result before writing the response. Practically this is rare — it only fails if Branch.ToApi() produced a value json cannot encode (e.g. an unsupported type like a channel, func, or a cyclic structure).","triggerScenarios":"A shared.Branch field of unmarshallable type (channel/func/cycle) introduced by a code change or corrupt DB row feeding ToApi().","commonSituations":"Custom builds with modified Branch/ToApi types; a plugin or fork adding non-serializable fields; corrupted rows producing unexpected values in custom field types with broken MarshalJSON.","solutions":["Read the logged '%v' detail to identify the offending field/type","Ensure all fields on shared.Branch are JSON-serializable (no channels, funcs, or cycles)","If a custom MarshalJSON was added to Branch, fix or remove it","Retry the request — transient corruption of in-memory state clears on restart"],"exampleFix":null,"handlingStrategy":"try-catch","validationCode":null,"typeGuard":null,"tryCatchPattern":"try {\n  const res = await api.getCurrentBranchByPlanId(projectId, body);\n} catch (err) {\n  if (err.status === 500 && String(err.message).startsWith('Error marshalling branches:')) {\n    // server-side serialization bug: report with server log detail\n    console.error('Response serialization failed on server; likely version mismatch', err.message);\n    return null;\n  }\n  throw err;\n}","preventionTips":["Keep client and server versions of shared.Branch in sync","Never add non-serializable fields (channels, funcs, cycles) to shared types","If forking, test ToApi() output with json.Marshal in CI","This is essentially never a client-side problem — treat as a server bug"],"tags":["json","serialization","http-500","plandex-server"],"backgroundTag":"json-marshaling-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"}