{"record":{"id":"7e8e0cbf21d08731","repo":"passbolt/passbolt_api","slug":"the-self-registration-data-could-not-be-validated","errorCode":null,"errorMessage":"The self registration data could not be validated.","messagePattern":"The self registration data could not be validated\\.","errorType":"validation","errorClass":"FormValidationException","httpStatus":400,"severity":"error","filePath":"plugins/PassboltCe/SelfRegistration/src/Service/DryRun/SelfRegistrationEmailDomainsDryRunService.php","lineNumber":39,"sourceCode":"use Cake\\Http\\Exception\\ForbiddenException;\nuse Cake\\ORM\\TableRegistry;\nuse Passbolt\\SelfRegistration\\Form\\DryRun\\SelfRegistrationEmailDomainsDryRunForm;\n\nclass SelfRegistrationEmailDomainsDryRunService extends SelfRegistrationAbstractDryRunService\n{\n    /**\n     * @param array $data data in the payload\n     * @return bool\n     * @throws \\Cake\\Http\\Exception\\ForbiddenException if no allowed domains are found in the settings.\n     * @throws \\Cake\\Http\\Exception\\ForbiddenException if the email is already registered.\n     * @throws \\App\\Error\\Exception\\FormValidationException if no valid email is provided in the payload.\n     * @throws \\Cake\\Http\\Exception\\InternalErrorException if the data in the DB is invalid.\n     */\n    public function canGuestSelfRegister(array $data): bool\n    {\n        $form = new SelfRegistrationEmailDomainsDryRunForm();\n        if (!$form->execute($data)) {\n            throw new FormValidationException(\n                __('The self registration data could not be validated.'),\n                $form\n            );\n        }\n\n        $allowedDomains = $this->getAllowedDomainsInSettings();\n\n        $email = $form->getData('email');\n        $this->checkEmailDomainIsAllowed($email, $allowedDomains);\n        $this->checkEmailNotPreviouslyRegistered($email);\n\n        return true;\n    }\n\n    /**\n     * @return array\n     * @throws \\Cake\\Http\\Exception\\ForbiddenException if no allowed domains are found in the settings.\n     * @throws \\Cake\\Http\\Exception\\InternalErrorException if the settings in DB are not valid.","sourceCodeStart":21,"sourceCodeEnd":57,"githubUrl":"https://github.com/passbolt/passbolt_api/blob/31c1bbc10f32808a607fa9bd81891e898779c0bc/plugins/PassboltCe/SelfRegistration/src/Service/DryRun/SelfRegistrationEmailDomainsDryRunService.php#L21-L57","documentation":"Thrown by SelfRegistrationEmailDomainsDryRunService::canGuestSelfRegister when the dry-run payload fails SelfRegistrationEmailDomainsDryRunForm validation. FormValidationException carries the form with per-field errors. The payload must be shaped so the email-domains check can evaluate it.","triggerScenarios":"Dry-run request missing the required 'email' field, containing a non-email string, or including unexpected/invalid keys rejected by the form.","commonSituations":"Clients omitting the email key; sending username only; empty payload fields; API version mismatch where the expected key changed.","solutions":["Read the form errors attached to the FormValidationException for exact field failures","Include a valid 'email' key in the dry-run payload","Ensure the payload is an associative array (JSON object) and not nested incorrectly","Compare against the fields expected by SelfRegistrationEmailDomainsDryRunForm"],"exampleFix":"// before\ncurl -d '{\"username\":\"ada@example.com\"}' /self-registration/dry-run\n// after\ncurl -d '{\"email\":\"ada@example.com\"}' /self-registration/dry-run","handlingStrategy":"validation","validationCode":"const payload = { email: 'ada@example.com' };\nif (!/^[^@\\s]+@[^@\\s]+\\.[^@\\s]+$/.test(payload.email ?? '')) {\n  throw new Error('email key is required and must be a valid address');\n}","typeGuard":"const isEmailPayload = (d) => typeof d === 'object' && d !== null && typeof d.email === 'string' && d.email.includes('@');","tryCatchPattern":"try {\n    await api.post('/self-registration/dry-run', payload);\n} catch (e) {\n    if (e.status === 400 && e.errors) { // FormValidationException payload\n        renderFieldErrors(e.errors);\n    }\n}","preventionTips":["Always include a well-formed 'email' field in the dry-run payload","Send a flat JSON object matching the form schema","Read the attached form errors for exact field names","Add client-side email format validation before the call"],"tags":["self-registration","validation","form"],"backgroundTag":"schema-validation-failed","analyzedSha":"31c1bbc10f32808a607fa9bd81891e898779c0bc","analyzedAt":"2026-09-17T00:04:38.960Z","contentChangedAt":"2026-09-17T00:04:38.960Z","schemaVersion":2},"datasetVersion":"2026-09-21T09:17:21.228Z"}