{"record":{"id":"a639e12cfb410111","repo":"passbolt/passbolt_api","slug":"could-not-validate-comment-data-commentsupdateservice","errorCode":null,"errorMessage":"Could not validate comment data.","messagePattern":"Could not validate comment data\\.","errorType":"validation","errorClass":"ValidationException","httpStatus":400,"severity":"error","filePath":"src/Service/Comments/CommentsUpdateService.php","lineNumber":90,"sourceCode":"        return $comment;\n    }\n\n    /**\n     * Manage validation errors.\n     *\n     * @param \\App\\Model\\Entity\\Comment $comment comment\n     * @throws \\Cake\\Http\\Exception\\ForbiddenException\n     * @throws \\App\\Error\\Exception\\ValidationException\n     * @return void\n     */\n    protected function _handleValidationErrors(Comment $comment): void\n    {\n        $errors = $comment->getErrors();\n        if (!empty($errors)) {\n            if (!empty(Hash::get($errors, 'user_id.is_owner'))) {\n                throw new ForbiddenException(__('You are not allowed to edit this comment.'));\n            }\n            throw new ValidationException(__('Could not validate comment data.'), $comment, $this->Comments);\n        }\n    }\n\n    /**\n     * Patch and validate comment entity from user input.\n     *\n     * @param string $userId The currently logged in user ID\n     * @param string $commentId The comment ID\n     * @param string $requestDataContent The comment 'content' data\n     * @return \\App\\Model\\Entity\\Comment $comment comment entity\n     */\n    protected function _patchAndValidateCommentEntity(string $userId, string $commentId, string $requestDataContent): Comment // phpcs:ignore\n    {\n        try {\n            $comment = $this->Comments->get($commentId);\n        } catch (RecordNotFoundException $e) {\n            throw new NotFoundException(__('The comment does not exist.'));\n        }","sourceCodeStart":72,"sourceCodeEnd":108,"githubUrl":"https://github.com/passbolt/passbolt_api/blob/31c1bbc10f32808a607fa9bd81891e898779c0bc/src/Service/Comments/CommentsUpdateService.php#L72-L108","documentation":"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.","triggerScenarios":"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.","commonSituations":"API clients sending empty or malformed comment content; schema changes adding new validation rules not honored by older clients; localized content exceeding column length.","solutions":["Inspect $comment->getErrors() returned in the exception to see the failing fields","Fix the request payload so it satisfies Comment table validation (e.g. non-empty content)","Re-run schema/migrations if new validation rules were added server-side"],"exampleFix":"// before\n$data = ['content' => ''];\n$service->update($userId, $commentId, json_encode($data));\n// after\n$data = ['content' => 'Updated comment text'];\n$service->update($userId, $commentId, json_encode($data));","handlingStrategy":"try-catch","validationCode":"$errors = $comment->getErrors();\n$isValid = empty($errors);","typeGuard":null,"tryCatchPattern":"try { $service->update($userId, $commentId, $data); } catch (ValidationException $e) { $errors = $e->getEntity()->getErrors(); /* surface field errors */ }","preventionTips":["Validate comment content length/format client-side","Keep client payloads in sync with table validation rules","Log entity errors to diagnose field-level failures"],"tags":["validation","comments","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"}