{"record":{"id":"eab57135a84fa637","repo":"plandex-ai/plandex","slug":"error-marshalling-response-v","errorCode":null,"errorMessage":"Error marshalling response: %v","messagePattern":"Error marshalling response: (.+?)","errorType":"http","errorClass":null,"httpStatus":500,"severity":"error","filePath":"app/server/handlers/file_maps.go","lineNumber":95,"sourceCode":"\t\treturn\n\t}\n\n\tselect {\n\tcase <-r.Context().Done():\n\t\thttp.Error(w, \"Request was cancelled\", http.StatusRequestTimeout)\n\t\treturn\n\tcase maps := <-results:\n\t\tif maps == nil {\n\t\t\thttp.Error(w, \"Mapping timed out\", http.StatusRequestTimeout)\n\t\t\treturn\n\t\t}\n\n\t\tresp := shared.GetFileMapResponse{\n\t\t\tMapBodies: maps,\n\t\t}\n\t\trespBytes, err := json.Marshal(resp)\n\t\tif err != nil {\n\t\t\thttp.Error(w, fmt.Sprintf(\"Error marshalling response: %v\", err), http.StatusInternalServerError)\n\t\t\treturn\n\t\t}\n\t\tw.Header().Set(\"Content-Type\", \"application/json\")\n\t\tw.Write(respBytes)\n\n\t\tlog.Printf(\"GetFileMapHandler success - writing response bytes: %d\", len(respBytes))\n\t}\n}\n\nfunc LoadCachedFileMapHandler(w http.ResponseWriter, r *http.Request) {\n\tlog.Println(\"Received request for LoadCachedFileMapHandler\")\n\n\tauth := Authenticate(w, r, true)\n\tif auth == nil {\n\t\treturn\n\t}\n\n\tvars := mux.Vars(r)","sourceCodeStart":77,"sourceCodeEnd":113,"githubUrl":"https://github.com/plandex-ai/plandex/blob/e2d772072efadbe41d2946d97d79be55532dbab5/app/server/handlers/file_maps.go#L77-L113","documentation":"GetFileMapHandler builds a shared.GetFileMapResponse from the file map bodies produced by the project map job queue and serializes it with encoding/json. This error is returned when json.Marshal fails on that response struct, which is extremely rare for JSON-tagged plain structs and normally indicates an unsupported value reached the payload.","triggerScenarios":"The marshalled GetFileMapResponse contains a value json.Marshal cannot encode — e.g. a field of an unsupported type (channel, func, complex number), a self-referential structure causing 'json: unsupported type', or a custom MarshalJSON method returning an error inside FileMapBodies.","commonSituations":"A shared package upgrade changed FileMapBodies/MapBodies to include a field with a non-serializable type or bad MarshalJSON; version mismatch between plandex-server and plandex-shared modules; a map job produced corrupt/typed-nil data that a custom marshaller chokes on.","solutions":["Check the %v detail in the response/log — 'json: unsupported type: X' pinpoints the exact field type causing the failure","Run 'go get github.com/plandex-ai/plandex-shared@latest' (or the matching version) so server and shared types are in sync, then rebuild","If a custom type inside the response defines MarshalJSON, fix or wrap it so it cannot fail, or make its output JSON-safe","As a robustness fix, log respBytes marshalling errors server-side and return a structured API error rather than a bare 500 string"],"exampleFix":"// before\nrespBytes, err := json.Marshal(resp)\nif err != nil {\n    http.Error(w, fmt.Sprintf(\"Error marshalling response: %v\", err), http.StatusInternalServerError)\n    return\n}\n// after\nrespBytes, err := json.Marshal(resp)\nif err != nil {\n    log.Printf(\"GetFileMapHandler: marshal error: %v\", err)\n    writeApiError(w, shared.ApiError{Type: shared.ApiErrorTypeOther, Status: http.StatusInternalServerError, Msg: \"Error marshalling response\"})\n    return\n}","handlingStrategy":"try-catch","validationCode":"// Go client: pre-serialize the equivalent payload to detect unsupported types before the call\ntype getReq struct{ MapInputs map[string]string }\nif _, err := json.Marshal(getReq{MapInputs: inputs}); err != nil {\n    return fmt.Errorf(\"refusing to call GetFileMap: %w\", err)\n}","typeGuard":"func isMarshalable(v any) bool {\n    _, err := json.Marshal(v)\n    return err == nil\n}","tryCatchPattern":"resp, err := client.GetFileMap(ctx, inputs)\nif err != nil {\n    if strings.Contains(err.Error(), \"Error marshalling response\") {\n        // 500 from server-side json.Marshal — log server details, upgrade shared types\n        return fmt.Errorf(\"file map response not serializable: %w\", err)\n    }\n    return err\n}","preventionTips":["Keep plandex-server and plandex-shared module versions in lockstep","Never add fields of unsupported types (chan, func, complex) to response structs","Give any custom MarshalJSON implementations full test coverage","Alert on 500 responses containing 'marshalling' — they indicate schema bugs, not transient faults"],"tags":["http","json","serialization","go"],"backgroundTag":"json-serialization-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"}