plandex-ai/plandex · error
Error marshalling response: %v
Error message
Error marshalling response: %v
What it means
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.
Source
Thrown at app/server/handlers/file_maps.go:95
return
}
select {
case <-r.Context().Done():
http.Error(w, "Request was cancelled", http.StatusRequestTimeout)
return
case maps := <-results:
if maps == nil {
http.Error(w, "Mapping timed out", http.StatusRequestTimeout)
return
}
resp := shared.GetFileMapResponse{
MapBodies: maps,
}
respBytes, err := json.Marshal(resp)
if err != nil {
http.Error(w, fmt.Sprintf("Error marshalling response: %v", err), http.StatusInternalServerError)
return
}
w.Header().Set("Content-Type", "application/json")
w.Write(respBytes)
log.Printf("GetFileMapHandler success - writing response bytes: %d", len(respBytes))
}
}
func LoadCachedFileMapHandler(w http.ResponseWriter, r *http.Request) {
log.Println("Received request for LoadCachedFileMapHandler")
auth := Authenticate(w, r, true)
if auth == nil {
return
}
vars := mux.Vars(r)View on GitHub (pinned to e2d772072e)
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
Example fix
// before
respBytes, err := json.Marshal(resp)
if err != nil {
http.Error(w, fmt.Sprintf("Error marshalling response: %v", err), http.StatusInternalServerError)
return
}
// after
respBytes, err := json.Marshal(resp)
if err != nil {
log.Printf("GetFileMapHandler: marshal error: %v", err)
writeApiError(w, shared.ApiError{Type: shared.ApiErrorTypeOther, Status: http.StatusInternalServerError, Msg: "Error marshalling response"})
return
} Defensive patterns
Strategy: try-catch
Validate before calling
// Go client: pre-serialize the equivalent payload to detect unsupported types before the call
type getReq struct{ MapInputs map[string]string }
if _, err := json.Marshal(getReq{MapInputs: inputs}); err != nil {
return fmt.Errorf("refusing to call GetFileMap: %w", err)
} Type guard
func isMarshalable(v any) bool {
_, err := json.Marshal(v)
return err == nil
} Try / catch
resp, err := client.GetFileMap(ctx, inputs)
if err != nil {
if strings.Contains(err.Error(), "Error marshalling response") {
// 500 from server-side json.Marshal — log server details, upgrade shared types
return fmt.Errorf("file map response not serializable: %w", err)
}
return err
} Prevention
- 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
When it happens
Trigger: 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.
Common situations: 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.
Understand the failure class
Background: "JSON serialization failed", "not JSON serializable", "Failed to serialize": why JSON marshaling errors happen and how to fix them — this error's family across 46 libraries.
Related errors
- Error marshalling response
- Error marshalling response
- error marshalling models: %v
- error marshalling model pack: %v
- error marshalling current plan settings: %v
AI-assisted analysis of plandex-ai/plandex@e2d772072e (2026-09-05).
Data as JSON: /api/errors/eab57135a84fa637.
Report an issue: GitHub.