plandex-ai/plandex · warning
Error decoding request: %v
Error message
Error decoding request: %v
What it means
GetFileMapHandler decodes the request body into shared.GetFileMapRequest using json.NewDecoder. If the body is not valid JSON or does not match the request schema, it logs 'Error decoding request: %v' (the %v is filled with the actual decode error) and returns HTTP 400 with the message.
Source
Thrown at app/server/handlers/file_maps.go:29
"sync"
shared "plandex-shared"
"github.com/gorilla/mux"
)
func GetFileMapHandler(w http.ResponseWriter, r *http.Request) {
log.Println("Received request for GetFileMapHandler")
auth := Authenticate(w, r, true)
if auth == nil {
log.Println("GetFileMapHandler: auth failed")
return
}
var req shared.GetFileMapRequest
if err := json.NewDecoder(r.Body).Decode(&req); err != nil {
http.Error(w, fmt.Sprintf("Error decoding request: %v", err), http.StatusBadRequest)
return
}
log.Println("GetFileMapHandler: checking limits")
if len(req.MapInputs) > shared.MaxContextMapPaths {
http.Error(w, fmt.Sprintf("Too many files to map: %d (max %d)", len(req.MapInputs), shared.MaxContextMapPaths), http.StatusBadRequest)
return
}
totalSize := 0
for path, input := range req.MapInputs {
// the client should be truncating inputs to the max size, but we'll check here too
if len(input) > shared.MaxContextMapSingleInputSize {
http.Error(w, fmt.Sprintf("File %s is too large: %d (max %d)", path, len(input), shared.MaxContextMapSingleInputSize), http.StatusBadRequest)
return
}
totalSize += len(input)View on GitHub (pinned to e2d772072e)
Solutions
- Log/print the exact decode error from the 400 response body and fix the JSON at the call site
- Verify the client sends application/json with a body matching shared.GetFileMapRequest: {"MapInputs": map[string]string}
- If middleware reads the body, re-set r.Body with io.NopCloser(bytes.NewBuffer(saved)) before the handler
- Ensure the client serializes with json.Marshal (or equivalent) rather than hand-built strings
Example fix
// before
http.Post(url, "text/plain", strings.NewReader("paths=/a.go,/b.go"))
// after
body, _ := json.Marshal(shared.GetFileMapRequest{MapInputs: inputs})
http.Post(url, "application/json", bytes.NewReader(body)) Defensive patterns
Strategy: validation
Validate before calling
// Client-side pre-send validation
body, err := json.Marshal(shared.GetFileMapRequest{MapInputs: inputs})
if err != nil { return fmt.Errorf("invalid request: %w", err) }
var probe shared.GetFileMapRequest
if err := json.Unmarshal(body, &probe); err != nil { return err } Type guard
func isValidGetFileMapRequest(body []byte) bool {
var req shared.GetFileMapRequest
return json.Unmarshal(body, &req) == nil && req.MapInputs != nil
} Prevention
- Always send Content-Type: application/json with json.Marshal output
- Round-trip the payload through Unmarshal before sending in tests
- Don't read r.Body in middleware without restoring it
- Log the raw body on decode failure to spot schema drift early
When it happens
Trigger: POST to the file-map endpoint with a malformed/empty body, invalid JSON syntax, wrong field types (e.g. MapInputs as an array instead of map[string]string), or a body already consumed by a middleware.
Common situations: Client sends form-encoded or gzip data instead of JSON; a proxy strips or truncates the body; client SDK version mismatch sends an older schema; Content-Type set but body left empty; double-reading r.Body (e.g. in logging middleware) leaving nothing for the decoder.
Related errors
- Error decoding request:
- Error marshalling response
- Error marshalling response: %v
- Error unmarshalling request:
- Custom model providers are not supported on Plandex Cloud
AI-assisted analysis of plandex-ai/plandex@e2d772072e (2026-09-05).
Data as JSON: /api/errors/e6b13ecca94b9f38.
Report an issue: GitHub.