plandex-ai/plandex · error

Error reading request body

Error message

Error reading request body

What it means

CreateBranchHandler reads the raw request body with io.ReadAll(r.Body) and returns HTTP 500 'Error reading request body' if the read fails. This means the handler never received a complete body from the transport — the failure is at the connection/request layer, before JSON parsing. Note the message intentionally omits err.Error() from the response.

Source

Thrown at app/server/handlers/branches.go:102

	if auth == nil {
		return
	}

	vars := mux.Vars(r)
	planId := vars["planId"]
	branch := vars["branch"]

	log.Println("planId: ", planId)

	plan := authorizePlan(w, planId, auth)
	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)

View on GitHub (pinned to e2d772072e)

Solutions

  1. Check that the client sends Content-Length or proper chunked encoding and completes the upload
  2. Raise proxy/body size limits if the request is large (e.g. nginx client_max_body_size)
  3. Increase client/proxy timeouts and retry on transient network failures

Example fix

// before
resp, err := http.Post(url, "application/json", brokenReader)
// after
body, _ := json.Marshal(req)
resp, err := http.Post(url, "application/json", bytes.NewReader(body)) // complete, sized body
Defensive patterns

Strategy: retry

Validate before calling

// client: send a fully buffered, sized body
body, err := json.Marshal(req)
if err != nil { return err }
httpReq, _ := http.NewRequest("POST", url, bytes.NewReader(body))
httpReq.ContentLength = int64(len(body))

Try / catch

// retry transient network failures
resp, err := client.Do(httpReq)
if err != nil {
    return fmt.Errorf("upload failed, retry: %w", err)
}

Prevention

When it happens

Trigger: POST to the create-branch endpoint when the client disconnects mid-upload, the request times out at a proxy, the body exceeds a server/proxy size limit and the connection is cut, or malformed chunked transfer encoding aborts the stream.

Common situations: Flaky network or client timeout while POSTing; a reverse proxy (nginx) buffering limit (client_max_body_size) closing the connection; a load balancer cutting idle uploads.

Related errors


AI-assisted analysis of plandex-ai/plandex@e2d772072e (2026-09-05). Data as JSON: /api/errors/302aa2c82719de42. Report an issue: GitHub.