{"record":{"id":"8ace9090b98ae025","repo":"plandex-ai/plandex","slug":"error-marshalling-branches","errorCode":null,"errorMessage":"Error marshalling branches: ","messagePattern":"Error marshalling branches: ","errorType":"http","errorClass":null,"httpStatus":500,"severity":"error","filePath":"app/server/handlers/branches.go","lineNumber":71,"sourceCode":"\t\t\treturn err\n\t\t}\n\n\t\tbranches = res\n\n\t\treturn nil\n\t})\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\tjsonBytes, err := json.Marshal(branches)\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 retrieved branches\")\n\n\tw.Write(jsonBytes)\n}\n\nfunc CreateBranchHandler(w http.ResponseWriter, r *http.Request) {\n\tlog.Println(\"Received request for CreateBranchHandler\")\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/branches.go#L53-L89","documentation":"ListBranchesHandler calls json.Marshal on the []*db.Branch slice and returns HTTP 500 'Error marshalling branches: <err>' if serialization fails. json.Marshal only errors on unsupported types (e.g. unexported fields with custom MarshalJSON returning an error, channels, funcs, or invalid UTF-8/cyclic data). In practice this is nearly always a bug in the Branch type's serialization, not in the request.","triggerScenarios":"The branches slice retrieved from ListPlanBranches contains a field whose MarshalJSON fails or an unsupported type (channel/func/cyclic reference) added to db.Branch; extremely rare in normal operation.","commonSituations":"A developer recently added a field to db.Branch (e.g. a custom struct or time-like type) with a broken MarshalJSON implementation; embedding a non-serializable type after a schema change.","solutions":["Read the wrapped marshal error in the server log to identify the offending field","Inspect db.Branch for recently added fields with custom MarshalJSON or unsupported types","Fix the MarshalJSON implementation or mark the field with `json:\"-\"` to skip it"],"exampleFix":"// before\ntype Branch struct {\n    Meta chan string `json:\"meta\"` // unsupported type\n}\n// after\ntype Branch struct {\n    Meta chan string `json:\"-\"` // excluded from JSON\n}","handlingStrategy":"try-catch","validationCode":null,"typeGuard":null,"tryCatchPattern":"// server-side: this is a serialization bug; log full error and fail fast in tests\ntestBranches := []*db.Branch{{...}}\nif _, err := json.Marshal(testBranches); err != nil {\n    t.Fatalf(\"Branch type not JSON-serializable: %v\", err)\n}","preventionTips":["Add a serialization smoke test for db.Branch whenever its fields change","Mark internal/non-serializable fields with `json:\"-\"`","Avoid custom MarshalJSON implementations unless tested","Keep db.Branch free of channels, funcs, and cyclic references"],"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-12T22:17:10.623Z"}