{"record":{"id":"d7db05ad45fead08","repo":"passbolt/passbolt_api","slug":"could-not-validate-group-user-data","errorCode":null,"errorMessage":"Could not validate group user data.","messagePattern":"Could not validate group user data\\.","errorType":"validation","errorClass":"ValidationException","httpStatus":422,"severity":"error","filePath":"src/Service/GroupsUsers/GroupsUsersAddService.php","lineNumber":159,"sourceCode":"        $groupUser = $this->groupsUsersTable->newEntity($data, ['accessibleFields' => $accessibleFields]);\n        if ($groupUser->hasErrors()) {\n            $this->handleValidationErrors($groupUser);\n        }\n\n        return $groupUser;\n    }\n\n    /**\n     * Handle group user validation errors.\n     *\n     * @param \\App\\Model\\Entity\\GroupsUser $groupUser The group user\n     * @throws \\App\\Error\\Exception\\ValidationException If the group user has errors.\n     * @return void\n     */\n    private function handleValidationErrors(GroupsUser $groupUser): void\n    {\n        $msg = __('Could not validate group user data.');\n        throw new ValidationException($msg, $groupUser, $this->groupsUsersTable);\n    }\n\n    /**\n     * Build the secrets entities.\n     *\n     * @param \\App\\Model\\Entity\\GroupsUser $groupUser The group user to add.\n     * @param array $missingAccessResourcesIds The missing access resources ids.\n     * @param array $secretsData The secrets data.\n     * @return array\n     * @throws \\App\\Error\\Exception\\ValidationException If it could not validate secrets data\n     * @throws \\App\\Error\\Exception\\ValidationException If some required secrets are missing\n     * @throws \\App\\Error\\Exception\\ValidationException If too many secrets are provided (Duplicate)\n     */\n    private function buildSecretsEntities(\n        UserAccessControl $uac,\n        GroupsUser $groupUser,\n        array $missingAccessResourcesIds,\n        array $secretsData = []","sourceCodeStart":141,"sourceCodeEnd":177,"githubUrl":"https://github.com/passbolt/passbolt_api/blob/31c1bbc10f32808a607fa9bd81891e898779c0bc/src/Service/GroupsUsers/GroupsUsersAddService.php#L141-L177","documentation":"GroupsUsersAddService::handleValidationErrors() throws App\\Error\\Exception\\ValidationException with this message when a GroupsUser entity (or associated Secret entities) fails validation while adding a user to a group. The exception carries the entity and groupsUsersTable for field-level details.","triggerScenarios":"POST to add a group user where validation fails: user already in the group, nonexistent user/group ids, missing required secrets for users added to a group with secrets, invalid secret payloads.","commonSituations":"Adding a user twice due to concurrent requests or UI retry; forgetting to provide encrypted secrets when required; referencing a user id from another instance.","solutions":["Check the response errors to see which field failed (user_id, group_id, secrets)","Verify the user is not already a member (GET group users) before adding","Ensure required Secret entities are provided for the added user when needed","Retry only after deduplicating pending add operations"],"exampleFix":null,"handlingStrategy":"validation","validationCode":"const members = await api.get(`/groups/${groupId}/users`);\nif (members.some(gu => gu.user.id === userId)) throw new Error('already a member');\nconst user = await api.get(`/users/${userId}`);\nif (!user) throw new Error('user does not exist');","typeGuard":null,"tryCatchPattern":"try {\n  await api.post(`/groups/${groupId}/users`, { user_id: userId, secrets });\n} catch (e) {\n  if (e.response?.body?.errors) console.error('GroupUser errors:', e.response.body.errors);\n  throw e;\n}","preventionTips":["Check existing membership before POSTing a group user","Provide encrypted Secret entities for the added user when the group requires them","Deduplicate concurrent add requests (idempotency on client side)","Verify user and group ids exist via their respective endpoints first"],"tags":["validation","groups-users","secrets"],"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-21T04:17:39.646Z"}