{"record":{"id":"6777f8fcd577b607","repo":"passbolt/passbolt_api","slug":"the-comment-id-is-not-valid-commentsupdateservice","errorCode":null,"errorMessage":"The comment id is not valid.","messagePattern":"The comment id is not valid\\.","errorType":"http","errorClass":"BadRequestException","httpStatus":400,"severity":"error","filePath":"src/Service/Comments/CommentsUpdateService.php","lineNumber":63,"sourceCode":"     */\n    public function __construct()\n    {\n        $this->Comments = TableRegistry::getTableLocator()->get('Comments');\n    }\n\n    /**\n     * Create a new comment for a resource.\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     * @throws \\Cake\\Http\\Exception\\BadRequestException if the validation failed\n     */\n    public function update(string $userId, string $commentId, string $requestDataContent): Comment\n    {\n        if (!Validation::uuid($commentId)) {\n            throw new BadRequestException(__('The comment id is not valid.'));\n        }\n\n        $comment = $this->_patchAndValidateCommentEntity($userId, $commentId, $requestDataContent);\n        $this->_handleValidationErrors($comment);\n\n        $this->Comments->save($comment, ['Comments.user_id' => $userId]);\n        $this->_handleValidationErrors($comment);\n\n        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","sourceCodeStart":45,"sourceCodeEnd":81,"githubUrl":"https://github.com/passbolt/passbolt_api/blob/31c1bbc10f32808a607fa9bd81891e898779c0bc/src/Service/Comments/CommentsUpdateService.php#L45-L81","documentation":"Passbolt throws this BadRequestException when the comment id supplied to CommentsUpdateService::update() is not a valid UUID. The library validates the identifier format before any database lookup to avoid useless queries and malformed SQL input. It is a client-side input error, not a server fault.","triggerScenarios":"Calling the comment update API (PATCH/PUT on a comment) with a comment id that is empty, an integer, a short token, or any string failing Validation::uuid().","commonSituations":"Client code passing a resource id instead of a comment id; truncated ids from URL parsing; test fixtures using fake non-UUID ids; switching database drivers where ids were serialized differently.","solutions":["Ensure the comment id passed to update() is a valid UUID string (e.g. '9d3f1c0a-...')","Fix the client-side variable mixup so the comment id, not the resource/user id, is passed","Log the incoming id and inspect the request route parameters for mis-mapped placeholders","Add a format check in the calling code before invoking the service"],"exampleFix":"// before\n$service->update($userId, $resourceId, $data);\n// after\nif (!Validation::uuid($commentId)) { throw new BadRequestException(__('The comment id is not valid.')); }\n$service->update($userId, $commentId, $data);","handlingStrategy":"validation","validationCode":"use Cake\\Validation\\Validation;\nif (!Validation::uuid($commentId)) { throw new \\InvalidArgumentException('commentId must be a UUID'); }","typeGuard":"function isValidUuid(string $id): bool { return preg_match('/^[0-9a-f]{8}-[0-9a-f]{4}-[0-9a-f]{4}-[0-9a-f]{4}-[0-9a-f]{12}$/i', $id) === 1; }","tryCatchPattern":"try { $service->update($userId, $commentId, $data); } catch (BadRequestException $e) { /* invalid id format: fix input */ }","preventionTips":["Always pass UUID strings for comment ids","Validate identifiers at the boundary (controller) before services","Map route placeholders explicitly to avoid id mixups"],"tags":["validation","uuid","comments","bad-request"],"backgroundTag":"invalid-identifier-format","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"}