{"record":{"id":"8ec8b23f6df01073","repo":"toeverything/AFFiNE","slug":"invalid-email-8ec8b2","errorCode":"invalid_email","errorMessage":"An invalid email provided: ${email}","messagePattern":"An invalid email provided: (.+?)","errorType":"exception","errorClass":"InvalidEmail","httpStatus":400,"severity":"warning","filePath":"packages/backend/server/src/core/utils/validators.ts","lineNumber":8,"sourceCode":"import z from 'zod';\n\nimport { InvalidEmail, InvalidPasswordLength } from '../../base';\n\nexport function assertValidEmail(email: string) {\n  const result = z.string().email().safeParse(email);\n  if (!result.success) {\n    throw new InvalidEmail({ email });\n  }\n}\n\nexport function assertValidPassword(\n  password: string,\n  { min, max }: { min: number; max: number }\n) {\n  const result = z.string().min(min).max(max).safeParse(password);\n\n  if (!result.success) {\n    throw new InvalidPasswordLength({ min, max });\n  }\n}\n\nexport const validators = {\n  assertValidEmail,\n  assertValidPassword,\n};","sourceCodeStart":1,"sourceCodeEnd":26,"githubUrl":"https://github.com/toeverything/AFFiNE/blob/26c515e050211269e911f7d9cfe162a26c83ed98/packages/backend/server/src/core/utils/validators.ts#L1-L26","documentation":"Thrown by assertValidEmail() when zod's string().email() schema fails to parse the given email. The validator is the single chokepoint used across auth/invitation flows to reject malformed email addresses before they reach the database or email-sending layer.","triggerScenarios":"assertValidEmail(value) is called with a value that is not a valid RFC-style email (missing '@', invalid domain, stray characters, empty string).","commonSituations":"User typo in a sign-up/invite form; whitespace or trailing characters pasted from a clipboard; non-string input coerced to garbage; test fixture with a placeholder email.","solutions":["Validate the email client-side (HTML5 input type=email + format check) before submitting.","Trim whitespace from the input before calling assertValidEmail.","Surface the field-level error to the user and re-prompt."],"exampleFix":"// before\nassertValidEmail(raw);\n\n// after\nassertValidEmail(raw.trim());","handlingStrategy":"validation","validationCode":"const trimmed = email.trim();\nif (!/^[^\\s@]+@[^\\s@]+\\.[^\\s@]+$/.test(trimmed)) { showEmailError(); return; }","typeGuard":"function isPlausibleEmail(value: string): boolean {\n  return /^[^\\s@]+@[^\\s@]+\\.[^\\s@]+$/.test(value.trim());\n}","tryCatchPattern":"try {\n  assertValidEmail(email);\n} catch (e) {\n  if (e?.code === 'invalid_email') { showFieldError('email'); return; }\n  throw e;\n}","preventionTips":["Trim whitespace before validating.","Use HTML5 input type=email plus a client-side regex pre-check.","Surface field-level errors back to the user."],"tags":["validation","email","zod","auth"],"backgroundTag":null,"analyzedSha":"26c515e050211269e911f7d9cfe162a26c83ed98","analyzedAt":"2026-08-12T13:15:16.447Z","schemaVersion":2},"datasetVersion":"2026-08-12T23:17:12.415Z"}