passbolt/passbolt_api · error · Cake\Web\Exception\ValidationException

Could not validate folder history data.

Error message

Could not validate folder history data.

What it means

FoldersHistoryTable::create() builds a folder history entity from the supplied data and, if the entity has validation errors, throws a ValidationException with 'Could not validate folder history data.' This enforces the model's validation rules (folder_id UUID, permission/ownership rules, etc.) before persisting the history snapshot.

Solutions

  1. Inspect $folderHistory->getErrors() (included in the ValidationException) to identify the failing field.
  2. Ensure the input array contains a valid folder `id` (UUID) since it is copied to `folder_id`.
  3. Run the model validation rules (validationDefault in FoldersHistoryTable) client-side or in a dry-run entity build before calling create().

Example fix

// before
$foldersHistoryTable->create(['id' => $someInt, 'name' => $name]);
// after
$entity = $foldersHistoryTable->newEntity($data);
if ($entity->getErrors()) { /* fix data */ }
$foldersHistoryTable->create(['id' => $folder->id, 'name' => $folder->name]);
Defensive patterns

Strategy: validation

Validate before calling

$errors = $foldersHistoryTable->buildEntity($data)->getErrors();
if (!empty($errors)) {
    // fix data before calling create()
    error_log(json_encode($errors));
}

Try / catch

try {
    $foldersHistoryTable->create($data);
} catch (ValidationException $e) {
    $errors = $e->getErrors(); // inspect per-field errors
    // correct $data and retry
}

Prevention

When it happens

Trigger: Calling create() (via folder history creation flows, e.g. after folder operations) with $data['id'] not a valid folder UUID or violating FoldersHistory entity rules — buildEntity() produces getErrors() non-empty.

Common situations: Folder history recorded with an id that isn't a valid folder UUID, data arrays shaped differently across plugin versions (the legacy second __() argument `true` hints at older CakePHP conventions), or callers passing an already-transformed DTO missing required keys.

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


AI-assisted analysis of passbolt/passbolt_api@31c1bbc10f (2026-09-17). Data as JSON: /api/errors/47c59f2ef70ac6d9. Report an issue: GitHub.

Appendix: source

Thrown at plugins/PassboltCe/Folders/src/Model/Table/FoldersHistoryTable.php:167

    /**
     * Create a new FolderHistory.
     *
     * @param array $data the data
     * @return \Passbolt\Folders\Model\Entity\FolderHistory
     * @throws \App\Error\Exception\ValidationException
     * @throws \Cake\Http\Exception\InternalErrorException
     */
    public function create(array $data): FolderHistory
    {
        // Folder.Id becomes FolderHistory.FolderId
        $data['folder_id'] = $data['id'];
        unset($data['id']);

        // Check validation rules.
        $folderHistory = $this->buildEntity($data);
        if ($folderHistory->getErrors()) {
            throw new ValidationException(__('Could not validate folder history data.', true), $folderHistory, $this);
        }
        $folderHistory = $this->save($folderHistory);

        // Check for errors while saving.
        if (!$folderHistory) {
            throw new InternalErrorException('Could not save the folder history.');
        }

        // Check for validation errors. (associated models too).
        if ($folderHistory->getErrors()) {
            throw new ValidationException(__('Could not validate folder history data.'), $folderHistory, $this);
        }

        return $folderHistory;
    }
}

View on GitHub (pinned to 31c1bbc10f)