plandex-ai/plandex · warning
Error parsing request body
Error message
Error parsing request body
What it means
LoadContextHandler unmarshals the request body into shared.LoadContextRequest with json.Unmarshal. Malformed JSON or fields with wrong types produce HTTP 400 'Error parsing request body'. This is a client-side payload problem, deliberately mapped to 400 rather than 500.
Source
Thrown at app/server/handlers/plans_context.go:184
plan := authorizePlan(w, planId, auth)
if plan == nil {
return
}
// read the request body
body, err := io.ReadAll(r.Body)
if err != nil {
log.Printf("Error reading request body: %v\n", err)
http.Error(w, "Error reading request body", http.StatusInternalServerError)
return
}
defer r.Body.Close()
var requestBody shared.LoadContextRequest
if err := json.Unmarshal(body, &requestBody); err != nil {
log.Printf("Error parsing request body: %v\n", err)
http.Error(w, "Error parsing request body", http.StatusBadRequest)
return
}
res, _ := loadContexts(loadContextsParams{
w: w,
r: r,
auth: auth,
loadReq: &requestBody,
plan: plan,
branchName: branchName,
})
if res == nil {
return
}
bytes, err := json.Marshal(res)
View on GitHub (pinned to e2d772072e)
Solutions
- Validate the JSON body (e.g. jq . payload.json) before sending
- Check that field names and types match shared.LoadContextRequest for your server version
- Ensure the client sends the raw JSON with Content-Type: application/json and isn't double-encoding
- Upgrade/align CLI and server versions so schemas match
Example fix
// before
{"contextPaths": "file.go"} // wrong type
// after
{"contextPaths": ["file.go"]} // matches []string in LoadContextRequest Defensive patterns
Strategy: validation
Validate before calling
// client-side: validate JSON shape before sending
var probe map[string]any
if err := json.Unmarshal(payload, &probe); err != nil {
return fmt.Errorf("invalid JSON payload: %w", err)
}
if _, ok := probe["contextPaths"].([]any); !ok {
return errors.New("contextPaths must be an array")
} Try / catch
var requestBody shared.LoadContextRequest
if err := json.Unmarshal(body, &requestBody); err != nil {
log.Printf("Error parsing request body: %v", err)
http.Error(w, "Error parsing request body: "+err.Error(), http.StatusBadRequest)
return
} Prevention
- Generate request payloads with the typed client/SDK, not hand-built strings
- Validate JSON locally (jq / json.Unmarshal probe) before POSTing
- Keep CLI and server versions aligned on shared request schemas
- Always send Content-Type: application/json and avoid double-encoding
When it happens
Trigger: Posting a body that is not valid JSON, empty body, wrong Content-Type with mangled payload, or fields whose JSON types don't match LoadContextRequest (e.g. contextPaths as string instead of array).
Common situations: CLI/SDK version mismatch sending an outdated request schema; hand-rolled curl with quoting errors; empty POST without body; double-encoded JSON strings.
Understand the failure class
Background: "failed to unmarshal" / json.Unmarshal errors: why parsing a response into a Go struct fails and how to fix it — this error's family across 23 libraries.
Related errors
- Error parsing request body
- Error parsing request body
- No project ids provided
- Error parsing request body
- Error parsing request body
AI-assisted analysis of plandex-ai/plandex@e2d772072e (2026-09-05).
Data as JSON: /api/errors/5c504585d417ae17.
Report an issue: GitHub.