{"record":{"id":"ad8524c1b4096766","repo":"BookStackApp/BookStack","slug":"errors-cannot-add-comment-to-draft","errorCode":null,"errorMessage":"errors.cannot_add_comment_to_draft","messagePattern":"errors\\.cannot_add_comment_to_draft","errorType":"exception","errorClass":"Exception","httpStatus":null,"severity":"error","filePath":"app/Activity/CommentRepo.php","lineNumber":48,"sourceCode":"    }\n\n    /**\n     * Start a query for comments visible to the user.\n     * @return Builder<Comment>\n     */\n    public function getQueryForVisible(): Builder\n    {\n        return Comment::query()->scopes('visible');\n    }\n\n    /**\n     * Create a new comment on an entity.\n     */\n    public function create(Entity $entity, string $html, ?int $parentId, string $contentRef): Comment\n    {\n        // Prevent comments being added to draft pages\n        if ($entity instanceof Page && $entity->draft) {\n            throw new \\Exception(trans('errors.cannot_add_comment_to_draft'));\n        }\n\n        // Validate parent ID\n        if ($parentId !== null) {\n            $parentCommentExists = Comment::query()\n                ->where('commentable_id', '=', $entity->id)\n                ->where('commentable_type', '=', $entity->getMorphClass())\n                ->where('local_id', '=', $parentId)\n                ->exists();\n            if (!$parentCommentExists) {\n                $parentId = null;\n            }\n        }\n\n        $userId = user()->id;\n        $comment = new Comment();\n\n        $comment->html = HtmlDescriptionFilter::filterFromString($html);","sourceCodeStart":30,"sourceCodeEnd":66,"githubUrl":"https://github.com/BookStackApp/BookStack/blob/18f8469a1c72f8cc8497e9372635e6dea5028071/app/Activity/CommentRepo.php#L30-L66","documentation":"Generic \\Exception (with a translated message) thrown in CommentRepo::create when the target entity is a draft Page; BookStack forbids comments on drafts since drafts are not visible to other users. Input at fault: a Page entity with draft=true passed to create().","triggerScenarios":"Thrown at app/Activity/CommentRepo.php:48 when the library encounters an invalid state.","commonSituations":"See trigger scenarios.","solutions":["Publish the draft page before adding comments","Only surface comment UI for pages that are published","If hit programmatically, check $page->draft before calling CommentRepo::create"],"exampleFix":null,"handlingStrategy":"validation","validationCode":null,"typeGuard":null,"tryCatchPattern":null,"preventionTips":[],"tags":[],"backgroundTag":null,"analyzedSha":"18f8469a1c72f8cc8497e9372635e6dea5028071","analyzedAt":"2026-09-02T19:49:33.068Z","contentChangedAt":null,"schemaVersion":2},"datasetVersion":"2026-09-10T02:17:09.455Z"}