{"record":{"id":"f9ac12063376c538","repo":"plandex-ai/plandex","slug":"error-unmarshalling-request-f9ac12","errorCode":null,"errorMessage":"Error unmarshalling request: ","messagePattern":"Error unmarshalling request: ","errorType":"http","errorClass":"http","httpStatus":500,"severity":"error","filePath":"app/server/handlers/sessions.go","lineNumber":33,"sourceCode":"\tshared \"plandex-shared\"\n)\n\nfunc CreateEmailVerificationHandler(w http.ResponseWriter, r *http.Request) {\n\tlog.Println(\"Received request for CreateEmailVerificationHandler\")\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: \"+err.Error(), http.StatusInternalServerError)\n\t\treturn\n\t}\n\n\tvar req shared.CreateEmailVerificationRequest\n\terr = json.Unmarshal(body, &req)\n\tif err != nil {\n\t\tlog.Printf(\"Error unmarshalling request: %v\\n\", err)\n\t\thttp.Error(w, \"Error unmarshalling request: \"+err.Error(), http.StatusInternalServerError)\n\t\treturn\n\t}\n\treq.Email = strings.ToLower(req.Email)\n\n\tvar hasAccount bool\n\tif req.UserId == \"\" {\n\t\tuser, err := db.GetUserByEmail(req.Email)\n\n\t\tif err != nil {\n\t\t\tlog.Printf(\"Error getting user: %v\\n\", err)\n\t\t\thttp.Error(w, \"Error getting user: \"+err.Error(), http.StatusInternalServerError)\n\t\t\treturn\n\t\t}\n\n\t\thasAccount = user != nil\n\t} else {\n\t\thasAccount = true\n","sourceCodeStart":15,"sourceCodeEnd":51,"githubUrl":"https://github.com/plandex-ai/plandex/blob/e2d772072efadbe41d2946d97d79be55532dbab5/app/server/handlers/sessions.go#L15-L51","documentation":"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.","triggerScenarios":"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.","commonSituations":"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.","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."],"exampleFix":"// before\n`{\"email\": \"User@Example.com\", \"requireUser\": \"true\"}`  // boolean as string\n// after\n`{\"email\": \"user@example.com\", \"requireUser\": true}`","handlingStrategy":"validation","validationCode":"// client-side validation before sending\npayload, err := json.Marshal(shared.CreateEmailVerificationRequest{\n    Email:        strings.ToLower(email),\n    UserId:       userId,\n    RequireUser:  requireUser,\n    RequireNoUser: requireNoUser,\n})\nif err != nil {\n    return fmt.Errorf(\"request does not marshal to valid JSON: %w\", err)\n}\nvar probe map[string]any\nif err := json.Unmarshal(payload, &probe); err != nil {\n    return fmt.Errorf(\"payload is not valid JSON: %w\", err)\n}","typeGuard":null,"tryCatchPattern":"// Go: decode into the shared type client-side first to catch schema mismatches early\nvar check shared.CreateEmailVerificationRequest\nif err := json.Unmarshal(payload, &check); err != nil {\n    return fmt.Errorf(\"payload does not match CreateEmailVerificationRequest schema: %w\", err)\n}\n// only then send the request","preventionTips":["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."],"tags":["go","json","request-validation","http"],"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-14T00:17:10.932Z"}