Skip to content

Commit

Permalink
Handle twig error
Browse files Browse the repository at this point in the history
  • Loading branch information
loevgaard committed Jun 11, 2024
1 parent b2fe101 commit d9db8bc
Showing 1 changed file with 16 additions and 3 deletions.
19 changes: 16 additions & 3 deletions src/Processor/NotificationProcessor.php
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@
use Symfony\Component\Workflow\Registry;
use Symfony\Component\Workflow\WorkflowInterface;
use Throwable;
use Twig\Error\Error;
use Webmozart\Assert\Assert;

final class NotificationProcessor implements NotificationProcessorInterface
Expand Down Expand Up @@ -64,11 +65,23 @@ function (NotificationInterface $notification) {
}
);
} catch (Throwable $e) {
$notification->addProcessingError(sprintf(
$message = sprintf(
'An unexpected error occurred when processing notification %d: %s',
(int) $notification->getId(),
$e->getMessage()
));
$e->getMessage(),
);

if ($e instanceof Error) {
$message = sprintf(
"A Twig error occurred when processing notification %d.\nTemplate: %s\nError: %s\nLine: %d",
(int) $notification->getId(),
(string) ($e->getSourceContext()?->getName() ?? 'Unknown'),
$e->getRawMessage(),
$e->getTemplateLine(),
);
}

$notification->addProcessingError($message);

$this->tryTransition($notification, NotificationWorkflow::TRANSITION_FAIL);

Expand Down

0 comments on commit d9db8bc

Please sign in to comment.