{"record":{"id":"de8786b97c995010","repo":"plandex-ai/plandex","slug":"error-creating-email-verification","errorCode":null,"errorMessage":"Error creating email verification: ","messagePattern":"Error creating email verification: ","errorType":"http","errorClass":"http","httpStatus":500,"severity":"error","filePath":"app/server/handlers/sessions.go","lineNumber":103,"sourceCode":"\tif !(os.Getenv(\"GOENV\") == \"development\" && os.Getenv(\"LOCAL_MODE\") == \"1\") {\n\t\t// create pin - 6 alphanumeric characters\n\t\tpinBytes, err := shared.GetRandomAlphanumeric(6)\n\t\tif err != nil {\n\t\t\tlog.Printf(\"Error generating random pin: %v\\n\", err)\n\t\t\thttp.Error(w, \"Error generating random pin: \"+err.Error(), http.StatusInternalServerError)\n\t\t\treturn\n\t\t}\n\n\t\t// get sha256 hash of pin\n\t\thashBytes := sha256.Sum256(pinBytes)\n\t\tpinHash := hex.EncodeToString(hashBytes[:])\n\n\t\t// create verification\n\t\terr = db.CreateEmailVerification(req.Email, req.UserId, pinHash)\n\n\t\tif err != nil {\n\t\t\tlog.Printf(\"Error creating email verification: %v\\n\", err)\n\t\t\thttp.Error(w, \"Error creating email verification: \"+err.Error(), http.StatusInternalServerError)\n\t\t\treturn\n\t\t}\n\n\t\terr = email.SendVerificationEmail(req.Email, string(pinBytes))\n\n\t\tif err != nil {\n\t\t\tlog.Printf(\"Error sending verification email: %v\\n\", err)\n\t\t\thttp.Error(w, \"Error sending verification email: \"+err.Error(), http.StatusInternalServerError)\n\t\t\treturn\n\t\t}\n\n\t\tres = shared.CreateEmailVerificationResponse{\n\t\t\tHasAccount: hasAccount,\n\t\t}\n\t} else {\n\t\tres = shared.CreateEmailVerificationResponse{\n\t\t\tHasAccount:  hasAccount,\n\t\t\tIsLocalMode: true,","sourceCodeStart":85,"sourceCodeEnd":121,"githubUrl":"https://github.com/plandex-ai/plandex/blob/e2d772072efadbe41d2946d97d79be55532dbab5/app/server/handlers/sessions.go#L85-L121","documentation":"This error is returned by CreateEmailVerificationHandler when db.CreateEmailVerification fails to persist a new email verification record (email, user id, SHA-256-hashed 6-char PIN) in the database. The handler wraps the underlying DB error with the prefix 'Error creating email verification: ' and responds with HTTP 500. It means the server could not create the verification row, so the PIN it generated is unusable.","triggerScenarios":"POST to the email-verification endpoint with a valid body when the database insert in db.CreateEmailVerification fails: database unavailable, schema/constraint violation (e.g. duplicate email/user verification row), failed migration, or connection pool exhaustion.","commonSituations":"Postgres not running or misconfigured DATABASE_URL during local development; the email_verifications table missing because migrations did not run; unique constraint conflicts when requesting a verification repeatedly for the same email; disk-full or connection-limit issues in production.","solutions":["Check the server log line for the wrapped underlying error to see the exact database failure","Verify the database is reachable and DATABASE_URL/env config is correct","Run pending migrations so the email_verifications table exists","Check for unique/constraint conflicts (existing verification for the same email) and delete stale rows","Retry the request once the database is healthy"],"exampleFix":"// before (app/server/handlers/sessions.go)\nerr = db.CreateEmailVerification(req.Email, req.UserId, pinHash)\nif err != nil {\n\thttp.Error(w, \"Error creating email verification: \"+err.Error(), http.StatusInternalServerError)\n\treturn\n}\n// after (delete stale verification first so re-requests don't violate constraints)\nif err := db.DeleteEmailVerification(req.Email); err != nil {\n\tlog.Printf(\"Error clearing old verification: %v\\n\", err)\n}\nerr = db.CreateEmailVerification(req.Email, req.UserId, pinHash)\nif err != nil {\n\tlog.Printf(\"Error creating email verification: %v\\n\", err)\n\thttp.Error(w, \"Error creating email verification: \"+err.Error(), http.StatusInternalServerError)\n\treturn\n}","handlingStrategy":"retry","validationCode":"// before calling the endpoint, ensure the service is reachable\nresp, err := http.Get(baseURL + \"/health\")\nif err != nil || resp.StatusCode != 200 {\n\treturn fmt.Errorf(\"backend database likely unavailable: %v\", err)\n}","typeGuard":null,"tryCatchPattern":"// Go client\nresp, err := http.Post(url, \"application/json\", body)\nif err != nil { return err }\nif resp.StatusCode == http.StatusInternalServerError {\n\t// transient DB issue: back off and retry a limited number of times\n\tfor i := 0; i < 3; i++ {\n\t\ttime.Sleep(time.Duration(1<<i) * time.Second)\n\t\t// retry request...\n\t}\n}","preventionTips":["Run database migrations as part of every deployment","Monitor DB connectivity and alert before users hit verification flows","Delete or upsert stale verification rows for an email before re-issuing","Keep DATABASE_URL and pool settings validated by a startup health check"],"tags":["database","http-500","go","email-verification"],"backgroundTag":"database-insert-failed","analyzedSha":"e2d772072efadbe41d2946d97d79be55532dbab5","analyzedAt":"2026-09-05T20:56:53.631Z","contentChangedAt":"2026-09-05T20:56:53.631Z","schemaVersion":2},"datasetVersion":"2026-09-12T22:17:10.623Z"}