{"record":{"id":"3661cb39a563d7e4","repo":"plandex-ai/plandex","slug":"invalid-domain-v","errorCode":null,"errorMessage":"invalid domain: %v","messagePattern":"invalid domain: (.+?)","errorType":"validation","errorClass":null,"httpStatus":500,"severity":"error","filePath":"app/server/handlers/orgs.go","lineNumber":96,"sourceCode":"\t}\n\n\tvar req shared.CreateOrgRequest\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\n\tvar apiErr *shared.ApiError\n\tvar org *db.Org\n\terr = db.WithTx(r.Context(), \"create org\", func(tx *sqlx.Tx) error {\n\t\tvar err error\n\t\tvar domain *string\n\t\tif req.AutoAddDomainUsers {\n\t\t\tif shared.IsEmailServiceDomain(auth.User.Domain) {\n\t\t\t\tlog.Printf(\"Invalid domain: %v\\n\", auth.User.Domain)\n\t\t\t\treturn fmt.Errorf(\"invalid domain: %v\", auth.User.Domain)\n\t\t\t}\n\n\t\t\tdomain = &auth.User.Domain\n\t\t}\n\n\t\t// create a new org\n\t\torg, err = db.CreateOrg(&req, auth.AuthToken.UserId, domain, tx)\n\n\t\tif err != nil {\n\t\t\tlog.Printf(\"Error creating org: %v\\n\", err)\n\t\t\treturn fmt.Errorf(\"error creating org: %v\", err)\n\t\t}\n\n\t\tif org.AutoAddDomainUsers && org.Domain != nil {\n\t\t\terr = db.AddOrgDomainUsers(org.Id, *org.Domain, tx)\n\n\t\t\tif err != nil {\n\t\t\t\tlog.Printf(\"Error adding org domain users: %v\\n\", err)","sourceCodeStart":78,"sourceCodeEnd":114,"githubUrl":"https://github.com/plandex-ai/plandex/blob/e2d772072efadbe41d2946d97d79be55532dbab5/app/server/handlers/orgs.go#L78-L114","documentation":"Returned from the create-org transaction when the request sets AutoAddDomainUsers=true but the authenticated user's email domain is an email-service domain (e.g. gmail.com, detected by shared.IsEmailServiceDomain). Auto-adding all users of such a public domain makes no sense and would leak org membership, so the server rejects it inside the WithTx and the handler returns 500 with this message.","triggerScenarios":"POST to the create-org endpoint with {\"autoAddDomainUsers\": true} while authenticated with an email whose domain is a public email provider (gmail.com, outlook.com, etc.).","commonSituations":"Client SDK sends autoAddDomainUsers:true by default; a developer testing with a personal Gmail/Hotmail account; a misconfigured user record whose Domain field defaults to a consumer mail provider.","solutions":["Set autoAddDomainUsers to false in the CreateOrgRequest (or omit it) when authenticating with a personal email-provider account","Use a work email on a company domain if you truly want domain-based auto-add","If the user record is wrong, fix the account's email/domain so shared.IsEmailServiceDomain returns false","On the server, consider returning 400/422 instead of 500 so clients can surface a clear message"],"exampleFix":"// before\n{ \"name\": \"acme\", \"autoAddDomainUsers\": true }  // authed as dev@gmail.com\n// after\n{ \"name\": \"acme\", \"autoAddDomainUsers\": false }","handlingStrategy":"validation","validationCode":"const EMAIL_DOMAINS = /@(gmail|googlemail|outlook|hotmail|yahoo|icloud|proton)\\./i\nif (req.autoAddDomainUsers && EMAIL_DOMAINS.test(userEmail)) {\n  req.autoAddDomainUsers = false // or switch to a work-email account first\n}\nawait client.CreateOrg(req)","typeGuard":"function canAutoAddDomainUsers(userEmail) {\n  return !/@(gmail|googlemail|outlook|hotmail|yahoo|icloud|proton)\\./i.test(userEmail)\n}","tryCatchPattern":"try {\n  await client.CreateOrg(req)\n} catch (err) {\n  if (String(err.message).startsWith('invalid domain')) {\n    req.autoAddDomainUsers = false\n    await client.CreateOrg(req)\n  }\n}","preventionTips":["Only set autoAddDomainUsers=true when signed in with a company-domain email","Treat public email-provider domains (gmail, outlook, etc.) as ineligible for domain auto-add","Fix user account email/domain upstream if it wrongly maps to a consumer provider"],"tags":["validation","orgs","domain"],"backgroundTag":"invalid-email-domain","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"}