{"record":{"id":"5c504585d417ae17","repo":"plandex-ai/plandex","slug":"error-parsing-request-body-5c5045","errorCode":null,"errorMessage":"Error parsing request body","messagePattern":"Error parsing request body","errorType":"http","errorClass":null,"httpStatus":400,"severity":"warning","filePath":"app/server/handlers/plans_context.go","lineNumber":184,"sourceCode":"\n\tplan := authorizePlan(w, planId, auth)\n\tif plan == nil {\n\t\treturn\n\t}\n\n\t// read the request body\n\tbody, err := io.ReadAll(r.Body)\n\tif err != nil {\n\t\tlog.Printf(\"Error reading request body: %v\\n\", err)\n\t\thttp.Error(w, \"Error reading request body\", http.StatusInternalServerError)\n\t\treturn\n\t}\n\tdefer r.Body.Close()\n\n\tvar requestBody shared.LoadContextRequest\n\tif err := json.Unmarshal(body, &requestBody); err != nil {\n\t\tlog.Printf(\"Error parsing request body: %v\\n\", err)\n\t\thttp.Error(w, \"Error parsing request body\", http.StatusBadRequest)\n\t\treturn\n\t}\n\n\tres, _ := loadContexts(loadContextsParams{\n\t\tw:          w,\n\t\tr:          r,\n\t\tauth:       auth,\n\t\tloadReq:    &requestBody,\n\t\tplan:       plan,\n\t\tbranchName: branchName,\n\t})\n\n\tif res == nil {\n\t\treturn\n\t}\n\n\tbytes, err := json.Marshal(res)\n","sourceCodeStart":166,"sourceCodeEnd":202,"githubUrl":"https://github.com/plandex-ai/plandex/blob/e2d772072efadbe41d2946d97d79be55532dbab5/app/server/handlers/plans_context.go#L166-L202","documentation":"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.","triggerScenarios":"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).","commonSituations":"CLI/SDK version mismatch sending an outdated request schema; hand-rolled curl with quoting errors; empty POST without body; double-encoded JSON strings.","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"],"exampleFix":"// before\n{\"contextPaths\": \"file.go\"}          // wrong type\n// after\n{\"contextPaths\": [\"file.go\"]}        // matches []string in LoadContextRequest","handlingStrategy":"validation","validationCode":"// client-side: validate JSON shape before sending\nvar probe map[string]any\nif err := json.Unmarshal(payload, &probe); err != nil {\n\treturn fmt.Errorf(\"invalid JSON payload: %w\", err)\n}\nif _, ok := probe[\"contextPaths\"].([]any); !ok {\n\treturn errors.New(\"contextPaths must be an array\")\n}","typeGuard":null,"tryCatchPattern":"var requestBody shared.LoadContextRequest\nif err := json.Unmarshal(body, &requestBody); err != nil {\n\tlog.Printf(\"Error parsing request body: %v\", err)\n\thttp.Error(w, \"Error parsing request body: \"+err.Error(), http.StatusBadRequest)\n\treturn\n}","preventionTips":["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"],"tags":["go","json","http-400","validation"],"backgroundTag":"json-unmarshal-failed","analyzedSha":"e2d772072efadbe41d2946d97d79be55532dbab5","analyzedAt":"2026-09-05T20:56:53.631Z","contentChangedAt":"2026-09-05T20:56:53.631Z","schemaVersion":2},"datasetVersion":"2026-09-14T05:17:10.506Z"}