Skip to content

Prevent hide real exception when handler from some reason close transaction/connection #14

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
wants to merge 1 commit into
base: 7.0
Choose a base branch
from
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
11 changes: 10 additions & 1 deletion Messenger/DoctrineTransactionMiddleware.php
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,7 @@ protected function handleForManager(EntityManagerInterface $entityManager, Envel

return $envelope;
} catch (\Throwable $exception) {
$entityManager->getConnection()->rollBack();
$this->tryRollBackTransaction($entityManager, $exception);

if ($exception instanceof HandlerFailedException) {
// Remove all HandledStamp from the envelope so the retry will execute all handlers again.
Expand All @@ -45,4 +45,13 @@ protected function handleForManager(EntityManagerInterface $entityManager, Envel
throw $exception;
}
}

private function tryRollBackTransaction(EntityManagerInterface $entityManager, \Throwable|\Exception $exception): void
{
try {
$entityManager->getConnection()->rollBack();
} catch (\Throwable $doctrineException) {
throw new HandlerFailedException($doctrineException->getMessage(), previous: $exception);
}
}
}