{"record":{"id":"742cd526b6234129","repo":"koala73/worldmonitor","slug":"company-is-required","errorCode":null,"errorMessage":"Company is required","messagePattern":"Company is required","errorType":"validation","errorClass":"ValidationError","httpStatus":400,"severity":"error","filePath":"server/worldmonitor/leads/v1/submit-contact.ts","lineNumber":165,"sourceCode":"    throw new ApiError(403, 'Bot verification failed', '');\n  }\n\n  const { email, name, organization, phone, message, source } = req;\n\n  if (!email || !EMAIL_RE.test(email)) {\n    throw new ValidationError([{ field: 'email', description: 'Invalid email' }]);\n  }\n\n  const emailDomain = email.split('@')[1]?.toLowerCase();\n  if (emailDomain && FREE_EMAIL_DOMAINS.has(emailDomain)) {\n    throw new ApiError(422, 'Please use your work email address', '');\n  }\n\n  if (!name || name.trim().length === 0) {\n    throw new ValidationError([{ field: 'name', description: 'Name is required' }]);\n  }\n  if (!organization || organization.trim().length === 0) {\n    throw new ValidationError([{ field: 'organization', description: 'Company is required' }]);\n  }\n  if (!phone || !PHONE_RE.test(phone.trim())) {\n    throw new ValidationError([{ field: 'phone', description: 'Valid phone number is required' }]);\n  }\n\n  const safeName = name.slice(0, MAX_FIELD);\n  const safeOrg = organization.slice(0, MAX_FIELD);\n  const safePhone = phone.trim().slice(0, 30);\n  const safeMsg = message ? message.slice(0, MAX_MESSAGE) : undefined;\n  const safeSource = source ? source.slice(0, 100) : 'enterprise-contact';\n\n  const convexUrl = process.env.CONVEX_URL;\n  if (!convexUrl) {\n    throw new ApiError(503, 'Service unavailable', '');\n  }\n\n  const client = new ConvexHttpClient(convexUrl);\n  try {","sourceCodeStart":147,"sourceCodeEnd":183,"githubUrl":"https://github.com/koala73/worldmonitor/blob/a96956387a927b8cd7aa34b0c41fca357e746be9/server/worldmonitor/leads/v1/submit-contact.ts#L147-L183","documentation":"Required-field validation on the contact form (submit-contact.ts:164): organization must be present AND organization.trim().length > 0, else a ValidationError on field 'organization' ('Company is required') is thrown. Checked after name, before phone — the handler reports one violation at a time in field order, so fixing name alone surfaces this next.","triggerScenarios":"Omitting the organization field; whitespace-only company input; solo users leaving 'Company' blank because they are independent; a single 'Full name' field being mapped to name with nothing mapped to organization.","commonSituations":"Contact forms with optional-looking company fields; B2B forms where freelancers have no employer; frontend/state mapping bugs that drop the organization key during serialization.","solutions":["Make Company a required input and validate non-blank after trim","Map your form's company/employer field explicitly to the organization key","Batch client-side validation so name+organization+phone all report together instead of drip-feeding server errors"],"exampleFix":"// before\nawait submitContact({ name, organization: '', ... }); // -> \"Company is required\"\n\n// after\nconst organization = rawOrg.trim();\nif (!organization) throw new Error('company required');\nawait submitContact({ name, organization, ... });","handlingStrategy":"validation","validationCode":"const organization = rawOrg.trim();\nif (!organization) { showFieldError('organization', 'Company is required'); return; }\nawait submitContact({ ...form, organization });","typeGuard":"function isNonBlankString(v: unknown): v is string {\n  return typeof v === 'string' && v.trim().length > 0;\n}","tryCatchPattern":"try { await submitContact(form); }\ncatch (e) {\n  if (isValidationError(e)) {\n    for (const v of e.violations ?? []) if (v.field === 'organization') showFieldError('organization', v.description);\n    return;\n  }\n  throw e;\n}","preventionTips":["Mark Company required in the UI, not just server-side","For solo users, suggest entering a personal/company label to clear the gate","Batch-validate name+organization+phone client-side to avoid drip-fed server errors"],"tags":["validation","required-field","form-input"],"backgroundTag":"missing-required-argument","analyzedSha":"a96956387a927b8cd7aa34b0c41fca357e746be9","analyzedAt":"2026-08-21T16:51:25.751Z","contentChangedAt":"2026-08-21T16:51:25.751Z","schemaVersion":2},"datasetVersion":"2026-09-14T05:17:10.506Z"}