Skip to content

Commit 8b8bffb

Browse files
committed
feature #39378 [Messenger] Use "warning" instead of "error" log level for RecoverableException (lyrixx)
This PR was merged into the 5.3-dev branch. Discussion ---------- [Messenger] Use "warning" instead of "error" log level for RecoverableException | Q | A | ------------- | --- | Branch? | 5.x | Bug fix? | no | New feature? | yes | Deprecations? | no | Tickets | | License | MIT | Doc PR | When one throw a `RecoverableExceptionInterface`, one knows somethings wrong occurs, so if an `error` should be emmited, it's in place where the exception is thrown. And, by extension, if nothing really wrong occurs (like a random network error), one may want to retry the message **without** any errors. That's why in this PR, if an exception of type `RecoverableExceptionInterface` is thrown, it uses `warning` insteand of `error` log level. So everything stay under the radar. Commits ------- a885ba8 [Messenger] Use "warning" intead of "error" log level for RecoverableException
2 parents 266a6bb + a885ba8 commit 8b8bffb

File tree

1 file changed

+13
-1
lines changed

1 file changed

+13
-1
lines changed

src/Symfony/Component/Messenger/EventListener/SendFailedMessageForRetryListener.php

Lines changed: 13 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,7 @@
1212

1313
use Psr\Container\ContainerInterface;
1414
use Psr\Log\LoggerInterface;
15+
use Psr\Log\LogLevel;
1516
use Symfony\Component\EventDispatcher\EventSubscriberInterface;
1617
use Symfony\Component\Messenger\Envelope;
1718
use Symfony\Component\Messenger\Event\WorkerMessageFailedEvent;
@@ -70,7 +71,18 @@ public function onMessageFailed(WorkerMessageFailedEvent $event)
7071
$delay = $retryStrategy->getWaitingTime($envelope, $throwable);
7172

7273
if (null !== $this->logger) {
73-
$this->logger->error('Error thrown while handling message {class}. Sending for retry #{retryCount} using {delay} ms delay. Error: "{error}"', $context + ['retryCount' => $retryCount, 'delay' => $delay, 'error' => $throwable->getMessage(), 'exception' => $throwable]);
74+
$logLevel = LogLevel::ERROR;
75+
if ($throwable instanceof RecoverableExceptionInterface) {
76+
$logLevel = LogLevel::WARNING;
77+
} elseif ($throwable instanceof HandlerFailedException) {
78+
foreach ($throwable->getNestedExceptions() as $nestedException) {
79+
if ($nestedException instanceof RecoverableExceptionInterface) {
80+
$logLevel = LogLevel::WARNING;
81+
break;
82+
}
83+
}
84+
}
85+
$this->logger->log($logLevel, 'Error thrown while handling message {class}. Sending for retry #{retryCount} using {delay} ms delay. Error: "{error}"', $context + ['retryCount' => $retryCount, 'delay' => $delay, 'error' => $throwable->getMessage(), 'exception' => $throwable]);
7486
}
7587

7688
// add the delay and retry stamp info

0 commit comments

Comments
 (0)
pFad - Phonifier reborn

Pfad - The Proxy pFad of © 2024 Garber Painting. All rights reserved.

Note: This service is not intended for secure transactions such as banking, social media, email, or purchasing. Use at your own risk. We assume no liability whatsoever for broken pages.


Alternative Proxies:

Alternative Proxy

pFad Proxy

pFad v3 Proxy

pFad v4 Proxy