{"record":{"id":"341e4c6f2307b9c1","repo":"plandex-ai/plandex","slug":"error-marshalling-response-341e4c","errorCode":null,"errorMessage":"Error marshalling response: ","messagePattern":"Error marshalling response: ","errorType":"http","errorClass":"http","httpStatus":500,"severity":"warning","filePath":"app/server/handlers/sessions.go","lineNumber":129,"sourceCode":"\t\t\thttp.Error(w, \"Error sending verification email: \"+err.Error(), http.StatusInternalServerError)\n\t\t\treturn\n\t\t}\n\n\t\tres = shared.CreateEmailVerificationResponse{\n\t\t\tHasAccount: hasAccount,\n\t\t}\n\t} else {\n\t\tres = shared.CreateEmailVerificationResponse{\n\t\t\tHasAccount:  hasAccount,\n\t\t\tIsLocalMode: true,\n\t\t}\n\t}\n\n\tbytes, err := json.Marshal(res)\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\tlog.Println(\"Successfully created email verification\")\n\n\tw.Write(bytes)\n}\n\nfunc CheckEmailPinHandler(w http.ResponseWriter, r *http.Request) {\n\tlog.Println(\"Received request for VerifyEmailPinHandler\")\n\n\t// read the request body\n\tbody, err := io.ReadAll(r.Body)\n\tif err != nil {\n\t\tlog.Printf(\"Error reading request body: %v\\n\", err)\n\t\thttp.Error(w, \"Error reading request body: \"+err.Error(), http.StatusInternalServerError)\n\t\treturn\n\t}","sourceCodeStart":111,"sourceCodeEnd":147,"githubUrl":"https://github.com/plandex-ai/plandex/blob/e2d772072efadbe41d2946d97d79be55532dbab5/app/server/handlers/sessions.go#L111-L147","documentation":"This error is returned when json.Marshal fails to serialize the CreateEmailVerificationResponse before writing it to the ResponseWriter. The handler responds with HTTP 500 prefixed 'Error marshalling response: '. This is nearly impossible with the plain response struct, so it almost always indicates a custom MarshalJSON implementation or an unexpected value in the struct.","triggerScenarios":"json.Marshal(res) failing on shared.CreateEmailVerificationResponse — practically only if a field has a custom marshaler that returns an error, or the shared module version in use has a field that cannot be marshaled (e.g. a bad custom type).","commonSituations":"Plandex-shared module upgraded/patched with a custom MarshalJSON that errors; build using a mismatched or vendored plandex-shared version; replacing the response struct with one containing unmarshalable types (channels, funcs, cyclic pointers).","solutions":["Check the log for the wrapped marshal error to see which field failed","Pin/restore a known-good version of the plandex-shared dependency","Remove or fix any custom MarshalJSON on CreateEmailVerificationResponse fields","Ensure the response struct contains only marshalable types"],"exampleFix":"// before\nbytes, err := json.Marshal(res)\nif err != nil {\n\thttp.Error(w, \"Error marshalling response: \"+err.Error(), http.StatusInternalServerError)\n\treturn\n}\n// after: guard with a safe fallback so clients never get a 500 for a plain struct\nbytes, err := json.Marshal(res)\nif err != nil {\n\tlog.Printf(\"Error marshalling response: %v\\n\", err)\n\tbytes, _ = json.Marshal(shared.CreateEmailVerificationResponse{HasAccount: false})\n}","handlingStrategy":"try-catch","validationCode":null,"typeGuard":null,"tryCatchPattern":"// server-side safe marshal\nbytes, err := json.Marshal(res)\nif err != nil {\n\tlog.Printf(\"marshal failed: %v\", err)\n\tbytes, _ = json.Marshal(shared.CreateEmailVerificationResponse{})\n}\nw.Write(bytes)","preventionTips":["Keep response structs free of custom marshalers and unmarshalable types","Pin the plandex-shared dependency version","Add a test that marshals every API response struct","Avoid embedding dynamic values in shared response types"],"tags":["json","serialization","go","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"}