passbolt/passbolt_api · error · App\Error\Exception\ValidationException
Could not validate folder relation data.
Error message
Could not validate folder relation data.
What it means
A ValidationException raised by FoldersRelationsCreateService::handleFolderRelationValidationErrors when a new FoldersRelation entity fails model validation during create. The folder relation (linking a folder/resource to its parent in a user tree) did not pass FoldersRelationsTable rules, and the exception carries the entity and table for detailed errors.
Solutions
- Read the entity errors in the 400 response to identify the failing field (usually foreign_model, foreign_id, or user_id).
- Use only valid foreign_model values ('Folder', 'Resource') and valid UUIDs for foreign_id and user_id.
- Ensure the referenced folder/resource actually exists and belongs to the same user tree context.
- Check for duplicates: a user should not already have an identical relation row.
Example fix
// before
{"foreign_model":"folder", "foreign_id":"abc"} // invalid: lowercase model, non-uuid id
// after
{"foreign_model":"Folder", "foreign_id":"8e3874ae-4b40-590b-b236-2c2648d88a3b"} Defensive patterns
Strategy: validation
Validate before calling
const UUID = /^[0-9a-f]{8}-[0-9a-f]{4}-[0-9a-f]{4}-[0-9a-f]{4}-[0-9a-f]{12}$/i;
function validateFolderRelation(rel) {
return ['Folder', 'Resource'].includes(rel.foreign_model)
&& UUID.test(rel.foreign_id ?? '')
&& UUID.test(rel.user_id ?? '');
} Try / catch
try {
await folderRelationsApi.create(rel);
} catch (e) {
if (e.response?.status === 400 && e.response.data?.errors) {
console.error('Relation validation failed:', e.response.data.errors);
}
throw e;
} Prevention
- Use exact foreign_model values: 'Folder' or 'Resource'.
- Validate all ids as UUIDs and confirm the referenced entities exist.
- Prevent duplicate relation rows per user/item.
- Rely on high-level folder/resource APIs instead of creating relations directly.
When it happens
Trigger: Folder or item creation/move flows calling FoldersRelationsCreateService::create with invalid relation data: unknown foreign model value (must be 'Folder' or 'Resource'), invalid user_id/foreign_id UUIDs, or a relation violating uniqueness/table rules.
Common situations: Plugins or scripts creating folder relations directly with wrong foreign_model strings, non-existent folder/resource ids, or duplicate relations for the same user; version mismatches where the enum of allowed foreign models changed.
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 validate folder data.
- Could not validate folder data.
- Could not validate password data.
- Could not validate the transfer data.
- Could not validate user data.
AI-assisted analysis of passbolt/passbolt_api@31c1bbc10f (2026-09-17).
Data as JSON: /api/errors/cc52233c6dc4326c.
Report an issue: GitHub.
Appendix: source
Thrown at plugins/PassboltCe/Folders/src/Service/FoldersRelations/FoldersRelationsCreateService.php:89
'user_id' => true,
'folder_parent_id' => true,
];
return $this->foldersRelationsTable->newEntity($folderRelationData, ['accessibleFields' => $accessibleFields]);
}
/**
* Handle folder relation validation errors.
*
* @param \Passbolt\Folders\Model\Entity\FoldersRelation $folderRelation The folder relation
* @return void
*/
private function handleFolderRelationValidationErrors(FoldersRelation $folderRelation): void
{
$errors = $folderRelation->getErrors();
if (!empty($errors)) {
$msg = __('Could not validate folder relation data.');
throw new ValidationException($msg, $folderRelation, $this->foldersRelationsTable);
}
}
}
View on GitHub (pinned to 31c1bbc10f)