plandex-ai/plandex · warning
Error parsing request body
Error message
Error parsing request body
What it means
CreateBranchHandler unmarshals the request body into shared.CreateBranchRequest and returns HTTP 400 'Error parsing request body' when json.Unmarshal fails. This is a client-side payload problem: the body is not valid JSON or does not match the expected structure. The server deliberately responds 400 (client error), not 500.
Source
Thrown at app/server/handlers/branches.go:113
if plan == nil {
return
}
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 func() {
log.Println("Closing request body")
r.Body.Close()
}()
var req shared.CreateBranchRequest
if err := json.Unmarshal(body, &req); err != nil {
log.Printf("Error parsing request body: %v\n", err)
http.Error(w, "Error parsing request body ", http.StatusBadRequest)
return
}
parentBranch, err := db.GetDbBranch(planId, branch)
if err != nil {
log.Printf("Error getting parent branch: %v\n", err)
http.Error(w, "Error getting parent branch: "+err.Error(), http.StatusInternalServerError)
return
}
ctx, cancel := context.WithCancel(r.Context())
err = db.ExecRepoOperation(db.ExecRepoOperationParams{
OrgId: auth.OrgId,
UserId: auth.User.Id,
PlanId: planId,
Branch: "main",View on GitHub (pinned to e2d772072e)
Solutions
- Validate the request body is well-formed JSON matching shared.CreateBranchRequest (name field as string)
- Set Content-Type: application/json and send the serialized struct, not raw text
- Check for client/server API version mismatch on CreateBranchRequest fields
- Test with curl -d '{"name":"my-branch"}' -H 'Content-Type: application/json'
Example fix
// before
http.Post(url, "text/plain", strings.NewReader(`{"name": "b"}`))
// after
http.Post(url, "application/json", bytes.NewBuffer([]byte(`{"name":"b"}`))) Defensive patterns
Strategy: validation
Validate before calling
// client: validate JSON before sending
body, err := json.Marshal(shared.CreateBranchRequest{Name: branchName})
if err != nil { return fmt.Errorf("invalid request: %w", err) }
if !json.Valid(body) { return errors.New("payload is not valid JSON") } Type guard
func isValidCreateBranchRequest(b []byte) bool {
var req shared.CreateBranchRequest
return json.Unmarshal(b, &req) == nil && req.Name != ""
} Try / catch
// check response status before decoding a success shape
if resp.StatusCode == http.StatusBadRequest {
var errResp struct{ Error string }
_ = json.NewDecoder(resp.Body).Decode(&errResp)
return fmt.Errorf("bad request: %s", errResp.Error)
} Prevention
- Always marshal a typed struct instead of hand-writing JSON strings
- Set Content-Type: application/json
- Validate JSON with json.Valid or a schema before sending
- Quote JSON payloads correctly in shell/curl commands
When it happens
Trigger: POST with a body that is not valid JSON (syntax errors, empty body, HTML error page from a proxy), wrong Content-Type causing a garbled body, or fields of the wrong type (e.g. "name": 123 instead of a string).
Common situations: Calling the API with curl and forgetting to quote/single-quote the JSON on the shell; sending form-encoded data instead of JSON; an API client version mismatch where the request struct changed; a proxy returning an HTML 502 page as the body.
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
- error unmarshalling JSON file: %v
- invalid json: %w
- error marshalling json: %w
AI-assisted analysis of plandex-ai/plandex@e2d772072e (2026-09-05).
Data as JSON: /api/errors/dd7ff8b9bf907d56.
Report an issue: GitHub.