{"record":{"id":"3f61c31942fd30e8","repo":"passbolt/passbolt_api","slug":"could-not-validate-favorite-data","errorCode":null,"errorMessage":"Could not validate favorite data.","messagePattern":"Could not validate favorite data\\.","errorType":"validation","errorClass":"ValidationException","httpStatus":400,"severity":"error","filePath":"src/Service/Favorites/FavoritesAddService.php","lineNumber":125,"sourceCode":"     */\n    protected function _handleValidationError(Favorite $favorite): void\n    {\n        $errors = $favorite->getErrors();\n\n        if (!empty($errors)) {\n            if (\n                isset($errors['foreign_key']['resource_exists'])\n                || isset($errors['foreign_key']['resource_is_not_soft_deleted'])\n                || isset($errors['foreign_key']['has_resource_access'])\n            ) {\n                throw new NotFoundException(__('The resource does not exist.'));\n            }\n\n            if (isset($errors['user_id']['favorite_unique'])) {\n                throw new BadRequestException(__('This record is already marked as favorite.'));\n            }\n\n            throw new ValidationException(__('Could not validate favorite data.'));\n        }\n    }\n}\n","sourceCodeStart":107,"sourceCodeEnd":129,"githubUrl":"https://github.com/passbolt/passbolt_api/blob/31c1bbc10f32808a607fa9bd81891e898779c0bc/src/Service/Favorites/FavoritesAddService.php#L107-L129","documentation":"Passbolt throws this ValidationException as the fallback when the favorite entity fails validation for reasons other than the specific resource-existence or uniqueness rules handled above. The message is generic; the real cause is in the entity errors.","triggerScenarios":"add() is called with payloads failing other Favorite table rules, e.g. missing user_id, invalid foreign_model, or malformed fields.","commonSituations":"API clients omitting required fields; changes to the Favorite validation rules not reflected in clients; wrong foreign_model value submitted.","solutions":["Log and inspect the validation errors on the entity to identify the failing rule","Supply all required fields (user_id, foreign_model, foreign_key) with valid values","Update the client payload format to match current Favorite validation rules"],"exampleFix":"// before\n$favoritesService->add($userId, ['foreign_key' => $resourceId]); // missing foreign_model\n// after\n$favoritesService->add($userId, ['foreign_model' => 'Resource', 'foreign_key' => $resourceId]);","handlingStrategy":"validation","validationCode":"$required = ['user_id', 'foreign_model', 'foreign_key'];\n$ok = !array_diff($required, array_keys($data)) && in_array($data['foreign_model'], ['Resource'], true);","typeGuard":null,"tryCatchPattern":"try { $favoritesService->add($userId, $data); } catch (ValidationException $e) { /* inspect entity errors for the failing rule */ }","preventionTips":["Send the complete favorite payload with all required fields","Keep clients updated with validation rule changes","Log entity errors when the generic message appears"],"tags":["validation","favorites","entity"],"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"}