plandex-ai/plandex · warning

error parsing request body: %v

Error message

error parsing request body: %v

What it means

TellPlanHandler unmarshals the raw request body into shared.TellPlanRequest with json.Unmarshal. Malformed or non-conforming JSON produces this error, an error notification, and an HTTP 400 'Error parsing request body'.

Source

Thrown at app/server/handlers/plans_exec.go:64

		return
	}

	body, err := io.ReadAll(r.Body)
	if err != nil {
		log.Printf("Error reading request body: %v\n", err)
		go notify.NotifyErr(notify.SeverityError, fmt.Errorf("error reading request body: %v", err))
		http.Error(w, "Error reading request body", http.StatusInternalServerError)
		return
	}
	defer func() {
		log.Println("Closing request body")
		r.Body.Close()
	}()

	var requestBody shared.TellPlanRequest
	if err := json.Unmarshal(body, &requestBody); err != nil {
		log.Printf("Error parsing request body: %v\n", err)
		go notify.NotifyErr(notify.SeverityError, fmt.Errorf("error parsing request body: %v", err))
		http.Error(w, "Error parsing request body", http.StatusBadRequest)
		return
	}

	_, apiErr := hooks.ExecHook(hooks.WillTellPlan, hooks.HookParams{
		Auth: auth,
		Plan: plan,
	})
	if apiErr != nil {
		go notify.NotifyErr(notify.SeverityError, fmt.Errorf("error executing will tell plan hook: %v", apiErr))
		writeApiError(w, *apiErr)
		return
	}

	orgUserConfig, err := db.GetOrgUserConfig(auth.User.Id, auth.OrgId)
	if err != nil {
		log.Printf("Error getting org user config: %v\n", err)
		http.Error(w, "Error getting org user config", http.StatusInternalServerError)

View on GitHub (pinned to e2d772072e)

Solutions

  1. Validate the JSON payload against TellPlanRequest's field types and re-send.
  2. Ensure the client sends Content-Type: application/json.
  3. Check for client/server version drift in the TellPlanRequest schema.
  4. Log the offending body (redacted) to pinpoint the malformed portion.

Example fix

// before
{"plan_id": 123}
// after
{"plan_id": "123"}
Defensive patterns

Strategy: validation

Validate before calling

// Client side: validate JSON before sending
payload, err := json.Marshal(shared.TellPlanRequest{PlanId: planId, Text: text})
if err != nil {
    return fmt.Errorf("invalid request: %w", err)
}
var probe map[string]any
if err := json.Unmarshal(payload, &probe); err != nil {
    return fmt.Errorf("payload not valid JSON: %w", err)
}

Type guard

func isValidJSON(b []byte) bool {
    var v any
    return json.Unmarshal(b, &v) == nil
}

Try / catch

var requestBody shared.TellPlanRequest
if err := json.Unmarshal(body, &requestBody); err != nil {
    http.Error(w, "Error parsing request body", http.StatusBadRequest)
    return
}

Prevention

When it happens

Trigger: Client POSTs to /tell with syntactically invalid JSON, wrong Content-Type payload (e.g. form-encoded), missing required fields where json.Unmarshal fails on type mismatch (e.g. string where number expected), or truncated body.

Common situations: Outdated client SDK sending the old request shape; curl tests with unescaped quotes; API version mismatch between client and server; gateway rewriting the body.

Related errors


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