{"record":{"id":"fd9b14d808c75668","repo":"passbolt/passbolt_api","slug":"could-not-delete-comment","errorCode":null,"errorMessage":"Could not delete comment.","messagePattern":"Could not delete comment\\.","errorType":"http","errorClass":"BadRequestException","httpStatus":400,"severity":"error","filePath":"src/Service/Comments/CommentsDeleteService.php","lineNumber":90,"sourceCode":"        // Delete the comment.\n        $this->Comments->delete($comment, ['Comments.user_id' => $userId]);\n        $this->_handleDeleteErrors($comment);\n    }\n\n    /**\n     * Manage delete errors\n     *\n     * @param \\App\\Model\\Entity\\Comment $comment comment\n     * @return void\n     */\n    private function _handleDeleteErrors(Comment $comment): void\n    {\n        $errors = $comment->getErrors();\n        if (!empty($errors)) {\n            if (isset($errors['user_id']['is_owner'])) {\n                throw new NotFoundException(__('The comment does not exist.'));\n            }\n            throw new BadRequestException(__('Could not delete comment.'));\n        }\n    }\n}\n","sourceCodeStart":72,"sourceCodeEnd":94,"githubUrl":"https://github.com/passbolt/passbolt_api/blob/31c1bbc10f32808a607fa9bd81891e898779c0bc/src/Service/Comments/CommentsDeleteService.php#L72-L94","documentation":"The fallback of CommentsDeleteService::_handleDeleteErrors(): the delete failed and produced validation errors, but none matched the known is_owner case. This is an unexpected persistence-side rejection surfaced as a 400 with a generic message.","triggerScenarios":"A delete aborted by an association/rule not anticipated by the service (e.g. a custom rule added by a plugin, or cascade/dependency rules rejecting the delete), leaving errors on the entity that aren't user_id.is_owner.","commonSituations":"Third-party plugins adding delete rules to Comments; schema constraints added via migration conflicting with the delete; unexpected entity state after a failed save.","solutions":["Log $comment->getErrors() server-side (enable debug) to see the actual failing rule.","Check for plugins/custom rules attached to the Comments table that could veto deletes.","Retry, and if it persists, inspect the comments table rules and DB constraints after recent migrations."],"exampleFix":null,"handlingStrategy":"retry","validationCode":"if (!isUuid(commentId)) throw new Error('invalid comment id'); // rule out client-side causes first","typeGuard":null,"tryCatchPattern":"try { await deleteComment(id, userId); }\ncatch (e) {\n  if (e.response?.status === 400 && /Could not delete comment/.test(e.response?.data?.message ?? '')) {\n    reportToServerLog(id, e); // unexpected rule rejected the delete — needs investigation\n    return; // do not blind-retry; surface to user\n  }\n  throw e;\n}","preventionTips":["Audit plugins/custom rules on the Comments table after installs","Run recent migrations and verify comments-table constraints","Capture comment.getErrors() server-side when this occurs to identify the rule"],"tags":["http-400","delete","comments"],"backgroundTag":"database-write-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"}