plandex-ai/plandex · error · http
Error unmarshalling request:
Error message
Error unmarshalling request:
What it means
After reading the body, CreateEmailVerificationHandler unmarshals it into shared.CreateEmailVerificationRequest with encoding/json. On any decode failure it responds 500 with "Error unmarshalling request: <err>". This means the body was received fine but is not valid JSON or does not match the expected request schema.
Source
Thrown at app/server/handlers/sessions.go:33
shared "plandex-shared"
)
func CreateEmailVerificationHandler(w http.ResponseWriter, r *http.Request) {
log.Println("Received request for CreateEmailVerificationHandler")
// read the request body
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: "+err.Error(), http.StatusInternalServerError)
return
}
var req shared.CreateEmailVerificationRequest
err = json.Unmarshal(body, &req)
if err != nil {
log.Printf("Error unmarshalling request: %v\n", err)
http.Error(w, "Error unmarshalling request: "+err.Error(), http.StatusInternalServerError)
return
}
req.Email = strings.ToLower(req.Email)
var hasAccount bool
if req.UserId == "" {
user, err := db.GetUserByEmail(req.Email)
if err != nil {
log.Printf("Error getting user: %v\n", err)
http.Error(w, "Error getting user: "+err.Error(), http.StatusInternalServerError)
return
}
hasAccount = user != nil
} else {
hasAccount = true
View on GitHub (pinned to e2d772072e)
Solutions
- Inspect the server log for the exact json error (e.g. "unexpected end of JSON input", "cannot unmarshal string into Go value of type bool") and fix the payload accordingly.
- Send a syntactically valid JSON object with the correct field types for CreateEmailVerificationRequest (email string, userId string, requireUser/requireNoUser booleans).
- Set Content-Type: application/json and send the body raw, not form-encoded.
- Update the client (CLI/UI) to the version matching the server so shared request types align.
- Validate the JSON locally (jq . or a JSON linter) before calling the endpoint.
Example fix
// before
`{"email": "User@Example.com", "requireUser": "true"}` // boolean as string
// after
`{"email": "user@example.com", "requireUser": true}` Defensive patterns
Strategy: validation
Validate before calling
// client-side validation before sending
payload, err := json.Marshal(shared.CreateEmailVerificationRequest{
Email: strings.ToLower(email),
UserId: userId,
RequireUser: requireUser,
RequireNoUser: requireNoUser,
})
if err != nil {
return fmt.Errorf("request does not marshal to valid JSON: %w", err)
}
var probe map[string]any
if err := json.Unmarshal(payload, &probe); err != nil {
return fmt.Errorf("payload is not valid JSON: %w", err)
} Try / catch
// Go: decode into the shared type client-side first to catch schema mismatches early
var check shared.CreateEmailVerificationRequest
if err := json.Unmarshal(payload, &check); err != nil {
return fmt.Errorf("payload does not match CreateEmailVerificationRequest schema: %w", err)
}
// only then send the request Prevention
- Build request bodies by marshaling the shared struct (plandex-shared) instead of hand-writing JSON strings.
- Use correct JSON types — booleans as true/false, not "true"; strings quoted.
- Validate JSON with jq or a linter before invoking the endpoint from scripts.
- Keep CLI/UI versions in sync with the server so shared request types match.
- Confirm Content-Type: application/json so bodies are not treated as form data.
When it happens
Trigger: Client sends an empty body; malformed JSON (trailing commas, unquoted keys); wrong Content-Type with form-encoded or plain-text data; JSON field type mismatches (e.g. "requireUser": "true" string instead of boolean); unknown casing is tolerated but missing/misspelled fields leave the struct zeroed.
Common situations: Older CLI/UI versions posting a request shape that changed after a shared-types update; hand-rolled scripts calling the endpoint with wrong JSON; gateway rewriting or gzip-encoding the body without the server handling it; forgetting to marshal nested request objects.
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 unmarshalling request:
- Error marshalling response
- Error decoding request: %v
- Error marshalling response: %v
- Error decoding request:
AI-assisted analysis of plandex-ai/plandex@e2d772072e (2026-09-05).
Data as JSON: /api/errors/f9ac12063376c538.
Report an issue: GitHub.