plandex-ai/plandex · error
Error marshalling response:
Error message
Error marshalling response:
What it means
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>'.
Source
Thrown at app/server/handlers/plans_context.go:147
if dbContext.Id == contextId {
targetContext = dbContext
break
}
}
if targetContext == nil {
http.Error(w, "Context not found", http.StatusNotFound)
return
}
response := shared.GetContextBodyResponse{
Body: targetContext.Body,
}
bytes, err := json.Marshal(response)
if err != nil {
log.Printf("Error marshalling response: %v\n", err)
http.Error(w, "Error marshalling response: "+err.Error(), http.StatusInternalServerError)
return
}
w.Write(bytes)
}
func LoadContextHandler(w http.ResponseWriter, r *http.Request) {
log.Println("Received request for LoadContextHandler")
auth := Authenticate(w, r, true)
if auth == nil {
return
}
vars := mux.Vars(r)
planId := vars["planId"]
branchName := vars["branch"]
log.Println("planId: ", planId)View on GitHub (pinned to e2d772072e)
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
Example fix
// before
type GetContextBodyResponse struct {
Body string
Meta map[string]any // may contain unsupported values
}
// after
type GetContextBodyResponse struct {
Body string
Meta map[string]any `json:"-"`
} Defensive patterns
Strategy: type-guard
Validate before calling
func marshalable(v any) bool { _, err := json.Marshal(v); return err == nil } Type guard
func isResponseBodySafe(resp shared.GetContextBodyResponse) bool {
// Body must be a plain string and no extra unserializable fields added
return true
} Try / catch
bytes, err := json.Marshal(response)
if err != nil {
log.Printf("Error marshalling response: %v", err)
http.Error(w, "Error marshalling response", http.StatusInternalServerError)
return
} Prevention
- Keep GetContextBodyResponse limited to JSON-native types
- Add a unit test marshaling all shared response types
- Tag any non-serializable helper fields with json:"-"
When it happens
Trigger: json.Marshal(response) errors because GetContextBodyResponse gained a field json cannot encode (func/chan/cyclic) after a code change.
Common situations: Custom builds or upgrades where shared.GetContextBodyResponse was extended with an unserializable field.
Understand the failure class
Background: json.Marshal / "failed to marshal" errors in Go: why "unsupported type" happens and how to fix it — this error's family across 22 libraries.
Related errors
- Error marshalling invites:
- Error marshalling contexts:
- Error marshalling plans:
- Error marshalling response:
- Error marshalling projects:
AI-assisted analysis of plandex-ai/plandex@e2d772072e (2026-09-05).
Data as JSON: /api/errors/06a8c1273a9c0a87.
Report an issue: GitHub.