{"record":{"id":"33aca7a2a9c948f8","repo":"plandex-ai/plandex","slug":"error-marshalling-response-33aca7","errorCode":null,"errorMessage":"Error marshalling response: ","messagePattern":"Error marshalling response: ","errorType":"http","errorClass":null,"httpStatus":500,"severity":"error","filePath":"app/server/handlers/projects.go","lineNumber":75,"sourceCode":"\n\t\treturn nil\n\t})\n\n\tif err != nil {\n\t\tlog.Printf(\"Error creating project: %v\\n\", err)\n\t\thttp.Error(w, \"Error creating project: \"+err.Error(), http.StatusInternalServerError)\n\t\treturn\n\t}\n\n\tresp := shared.CreateProjectResponse{\n\t\tId: projectId,\n\t}\n\n\tbytes, err := json.Marshal(resp)\n\n\tif err != nil {\n\t\tlog.Printf(\"Error marshalling response: %v\\n\", err)\n\t\thttp.Error(w, \"Error marshalling response: \"+err.Error(), http.StatusInternalServerError)\n\t\treturn\n\t}\n\n\tw.Write(bytes)\n\n\tlog.Println(\"Successfully created project\", projectId)\n}\n\nfunc ListProjectsHandler(w http.ResponseWriter, r *http.Request) {\n\tlog.Println(\"Received request for ListProjectsHandler\")\n\n\tauth := Authenticate(w, r, true)\n\tif auth == nil {\n\t\treturn\n\t}\n\n\trows, err := db.Conn.Query(\"SELECT id, name FROM projects WHERE org_id = $1\", auth.OrgId)\n","sourceCodeStart":57,"sourceCodeEnd":93,"githubUrl":"https://github.com/plandex-ai/plandex/blob/e2d772072efadbe41d2946d97d79be55532dbab5/app/server/handlers/projects.go#L57-L93","documentation":"After a successful create, the handler marshals the CreateProjectResponse (an {\"id\": ...} struct) with encoding/json. json.Marshal of a plain string field essentially cannot fail in practice; if it does, the handler returns 500 with the marshal error text.","triggerScenarios":"Practically unreachable: would require resp to contain a value json.Marshal cannot encode. CreateProjectResponse holds only an Id string, so this branch is defensive dead code.","commonSituations":"You should essentially never hit this; seeing it implies the shared.CreateProjectResponse type was modified to include unsupported types such as channels, funcs, or cyclic pointers.","solutions":["Read the appended err.Error() in the log/response to see which field failed to marshal.","Inspect shared.CreateProjectResponse for recently added fields with unsupported types (chan, func, sync values, cycles).","Fix the response struct (use a supported type or add MarshalJSON) and rebuild the server.","Add a unit test marshalling the response type to catch regressions."],"exampleFix":null,"handlingStrategy":"try-catch","validationCode":null,"typeGuard":null,"tryCatchPattern":"body, err := io.ReadAll(res.Body)\nif err != nil {\n\treturn err\n}\nif res.StatusCode != http.StatusOK {\n\treturn fmt.Errorf(\"create project failed: %s\", string(body))\n}","preventionTips":["Keep response DTOs limited to JSON-safe types (strings, numbers, bools, slices, maps).","Add a CI test that marshals every shared response type.","Avoid embedding unserializable values (chan, func, sync primitives) in response structs.","Review any custom MarshalJSON implementations for error paths."],"tags":["go","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"}