passbolt/passbolt_api · error · BadRequestException
Could not delete comment.
Error message
Could not delete comment.
What it means
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.
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.
Defensive patterns
Strategy: retry
Validate before calling
if (!isUuid(commentId)) throw new Error('invalid comment id'); // rule out client-side causes first Try / catch
try { await deleteComment(id, userId); }
catch (e) {
if (e.response?.status === 400 && /Could not delete comment/.test(e.response?.data?.message ?? '')) {
reportToServerLog(id, e); // unexpected rule rejected the delete — needs investigation
return; // do not blind-retry; surface to user
}
throw e;
} Prevention
- 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
When it happens
Trigger: 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.
Common situations: Third-party plugins adding delete rules to Comments; schema constraints added via migration conflicting with the delete; unexpected entity state after a failed save.
Related errors
- Could not validate comment data.
- The comment does not exist.
- The comment id is not valid.
- Account recovery is disabled. Key backup is not supported.
- Account recovery is mandatory. Please provide the mandatory…
AI-assisted analysis of passbolt/passbolt_api@31c1bbc10f (2026-09-17).
Data as JSON: /api/errors/fd9b14d808c75668.
Report an issue: GitHub.
Appendix: source
Thrown at src/Service/Comments/CommentsDeleteService.php:90
// Delete the comment.
$this->Comments->delete($comment, ['Comments.user_id' => $userId]);
$this->_handleDeleteErrors($comment);
}
/**
* Manage delete errors
*
* @param \App\Model\Entity\Comment $comment comment
* @return void
*/
private function _handleDeleteErrors(Comment $comment): void
{
$errors = $comment->getErrors();
if (!empty($errors)) {
if (isset($errors['user_id']['is_owner'])) {
throw new NotFoundException(__('The comment does not exist.'));
}
throw new BadRequestException(__('Could not delete comment.'));
}
}
}
View on GitHub (pinned to 31c1bbc10f)