passbolt/passbolt_api · error · ValidationException
Could not validate favorite data.
Error message
Could not validate favorite data.
What it means
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.
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
Example fix
// before $favoritesService->add($userId, ['foreign_key' => $resourceId]); // missing foreign_model // after $favoritesService->add($userId, ['foreign_model' => 'Resource', 'foreign_key' => $resourceId]);
Defensive patterns
Strategy: validation
Validate before calling
$required = ['user_id', 'foreign_model', 'foreign_key']; $ok = !array_diff($required, array_keys($data)) && in_array($data['foreign_model'], ['Resource'], true);
Try / catch
try { $favoritesService->add($userId, $data); } catch (ValidationException $e) { /* inspect entity errors for the failing rule */ } Prevention
- Send the complete favorite payload with all required fields
- Keep clients updated with validation rule changes
- Log entity errors when the generic message appears
When it happens
Trigger: add() is called with payloads failing other Favorite table rules, e.g. missing user_id, invalid foreign_model, or malformed fields.
Common situations: API clients omitting required fields; changes to the Favorite validation rules not reflected in clients; wrong foreign_model value submitted.
Understand the failure class
Background: Schema validation failed / invalid input schema: payload rejected because its shape doesn't match the expected schema — this error's family across 28 libraries.
Related errors
- Could not delete favorite.
- Could not validate action data.
- Could not validate comment data.
- Could not validate directory entry data.
- Could not validate folder history data.
AI-assisted analysis of passbolt/passbolt_api@31c1bbc10f (2026-09-17).
Data as JSON: /api/errors/3f61c31942fd30e8.
Report an issue: GitHub.
Appendix: source
Thrown at src/Service/Favorites/FavoritesAddService.php:125
*/
protected function _handleValidationError(Favorite $favorite): void
{
$errors = $favorite->getErrors();
if (!empty($errors)) {
if (
isset($errors['foreign_key']['resource_exists'])
|| isset($errors['foreign_key']['resource_is_not_soft_deleted'])
|| isset($errors['foreign_key']['has_resource_access'])
) {
throw new NotFoundException(__('The resource does not exist.'));
}
if (isset($errors['user_id']['favorite_unique'])) {
throw new BadRequestException(__('This record is already marked as favorite.'));
}
throw new ValidationException(__('Could not validate favorite data.'));
}
}
}
View on GitHub (pinned to 31c1bbc10f)