{"record":{"id":"06a8c1273a9c0a87","repo":"plandex-ai/plandex","slug":"error-marshalling-response-06a8c1","errorCode":null,"errorMessage":"Error marshalling response: ","messagePattern":"Error marshalling response: ","errorType":"http","errorClass":null,"httpStatus":500,"severity":"error","filePath":"app/server/handlers/plans_context.go","lineNumber":147,"sourceCode":"\t\tif dbContext.Id == contextId {\n\t\t\ttargetContext = dbContext\n\t\t\tbreak\n\t\t}\n\t}\n\n\tif targetContext == nil {\n\t\thttp.Error(w, \"Context not found\", http.StatusNotFound)\n\t\treturn\n\t}\n\n\tresponse := shared.GetContextBodyResponse{\n\t\tBody: targetContext.Body,\n\t}\n\n\tbytes, err := json.Marshal(response)\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\nfunc LoadContextHandler(w http.ResponseWriter, r *http.Request) {\n\tlog.Println(\"Received request for LoadContextHandler\")\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\"]\n\tbranchName := vars[\"branch\"]\n\tlog.Println(\"planId: \", planId)","sourceCodeStart":129,"sourceCodeEnd":165,"githubUrl":"https://github.com/plandex-ai/plandex/blob/e2d772072efadbe41d2946d97d79be55532dbab5/app/server/handlers/plans_context.go#L129-L165","documentation":"GetContextBodyHandler json.Marshal's shared.GetContextBodyResponse{Body: string}. Marshaling a struct with a plain string body cannot fail under normal conditions; an error here indicates an unexpected model change (unsupported field type, cycle) and yields HTTP 500 'Error marshalling response: <err>'.","triggerScenarios":"json.Marshal(response) errors because GetContextBodyResponse gained a field json cannot encode (func/chan/cyclic) after a code change.","commonSituations":"Custom builds or upgrades where shared.GetContextBodyResponse was extended with an unserializable field.","solutions":["Read err.Error() to find the unsupported type/field","Audit recent changes to shared.GetContextBodyResponse","Tag unserializable fields with json:\"-\" or implement MarshalJSON","Deploy a known-good build to confirm the cause"],"exampleFix":"// before\ntype GetContextBodyResponse struct {\n\tBody string\n\tMeta map[string]any // may contain unsupported values\n}\n// after\ntype GetContextBodyResponse struct {\n\tBody string\n\tMeta map[string]any `json:\"-\"`\n}","handlingStrategy":"type-guard","validationCode":"func marshalable(v any) bool { _, err := json.Marshal(v); return err == nil }","typeGuard":"func isResponseBodySafe(resp shared.GetContextBodyResponse) bool {\n\t// Body must be a plain string and no extra unserializable fields added\n\treturn true\n}","tryCatchPattern":"bytes, err := json.Marshal(response)\nif err != nil {\n\tlog.Printf(\"Error marshalling response: %v\", err)\n\thttp.Error(w, \"Error marshalling response\", http.StatusInternalServerError)\n\treturn\n}","preventionTips":["Keep GetContextBodyResponse limited to JSON-native types","Add a unit test marshaling all shared response types","Tag any non-serializable helper fields with json:\"-\""],"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"}