passbolt/passbolt_api · error · ValidationException

Could not validate comment data.

Error message

Could not validate comment data.

What it means

Passbolt throws this ValidationException when the patched comment entity fails table validation and the errors are not ownership-related. The exception carries the entity and table so the caller/serializer can expose field-level validation errors.

Solutions

  1. Inspect $comment->getErrors() returned in the exception to see the failing fields
  2. Fix the request payload so it satisfies Comment table validation (e.g. non-empty content)
  3. Re-run schema/migrations if new validation rules were added server-side

Example fix

// before
$data = ['content' => ''];
$service->update($userId, $commentId, json_encode($data));
// after
$data = ['content' => 'Updated comment text'];
$service->update($userId, $commentId, json_encode($data));
Defensive patterns

Strategy: try-catch

Validate before calling

$errors = $comment->getErrors();
$isValid = empty($errors);

Try / catch

try { $service->update($userId, $commentId, $data); } catch (ValidationException $e) { $errors = $e->getEntity()->getErrors(); /* surface field errors */ }

Prevention

When it happens

Trigger: update() patches the comment with request data that violates Comment table rules (e.g. empty content, oversized field, invalid format) and _handleValidationErrors finds non-is_owner errors.

Common situations: API clients sending empty or malformed comment content; schema changes adding new validation rules not honored by older clients; localized content exceeding column length.

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/a639e12cfb410111. Report an issue: GitHub.

Appendix: source

Thrown at src/Service/Comments/CommentsUpdateService.php:90

        return $comment;
    }

    /**
     * Manage validation errors.
     *
     * @param \App\Model\Entity\Comment $comment comment
     * @throws \Cake\Http\Exception\ForbiddenException
     * @throws \App\Error\Exception\ValidationException
     * @return void
     */
    protected function _handleValidationErrors(Comment $comment): void
    {
        $errors = $comment->getErrors();
        if (!empty($errors)) {
            if (!empty(Hash::get($errors, 'user_id.is_owner'))) {
                throw new ForbiddenException(__('You are not allowed to edit this comment.'));
            }
            throw new ValidationException(__('Could not validate comment data.'), $comment, $this->Comments);
        }
    }

    /**
     * Patch and validate comment entity from user input.
     *
     * @param string $userId The currently logged in user ID
     * @param string $commentId The comment ID
     * @param string $requestDataContent The comment 'content' data
     * @return \App\Model\Entity\Comment $comment comment entity
     */
    protected function _patchAndValidateCommentEntity(string $userId, string $commentId, string $requestDataContent): Comment // phpcs:ignore
    {
        try {
            $comment = $this->Comments->get($commentId);
        } catch (RecordNotFoundException $e) {
            throw new NotFoundException(__('The comment does not exist.'));
        }

View on GitHub (pinned to 31c1bbc10f)