-
Notifications
You must be signed in to change notification settings - Fork 11
feat: improve shopware exception ignoring #28
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
base: main
Are you sure you want to change the base?
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,36 @@ | ||
| <?php | ||
|
|
||
| namespace Frosh\SentryBundle\Integration; | ||
|
|
||
| use Sentry\ExceptionDataBag; | ||
| use Symfony\Contracts\EventDispatcher\Event; | ||
|
|
||
| class FilterExceptionEvent extends Event | ||
| { | ||
|
|
||
| /** | ||
| * @param ExceptionDataBag[] $exceptions | ||
| */ | ||
| public function __construct(private array $exceptions) | ||
| { | ||
| } | ||
|
|
||
| /** | ||
| * @return ExceptionDataBag[] | ||
| */ | ||
| public function getExceptions(): array | ||
| { | ||
| return $this->exceptions; | ||
| } | ||
|
|
||
| /** | ||
| * @param ExceptionDataBag[] $exceptions | ||
| */ | ||
| public function setExceptions(array $exceptions): void | ||
| { | ||
| $this->exceptions = $exceptions; | ||
| } | ||
|
coderabbitai[bot] marked this conversation as resolved.
|
||
|
|
||
|
|
||
|
|
||
| } | ||
| Original file line number | Diff line number | Diff line change | ||||||||||||
|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|
|
|
@@ -5,34 +5,25 @@ | |||||||||||||
| use Sentry\Event; | ||||||||||||||
| use Sentry\Integration\IntegrationInterface; | ||||||||||||||
| use Sentry\State\Scope; | ||||||||||||||
| use Symfony\Contracts\EventDispatcher\EventDispatcherInterface; | ||||||||||||||
|
|
||||||||||||||
| class UseShopwareExceptionIgnores implements IntegrationInterface | ||||||||||||||
| { | ||||||||||||||
| /** | ||||||||||||||
| * @param array<string, array{log_level: string}> $exceptions | ||||||||||||||
| */ | ||||||||||||||
| public function __construct(private readonly array $exceptions) {} | ||||||||||||||
| public function __construct(private readonly EventDispatcherInterface $eventDispatcher) | ||||||||||||||
| { | ||||||||||||||
| } | ||||||||||||||
|
|
||||||||||||||
| public function setupOnce(): void | ||||||||||||||
| { | ||||||||||||||
| $exceptions = $this->exceptions; | ||||||||||||||
|
|
||||||||||||||
| Scope::addGlobalEventProcessor(function (Event $event) use ($exceptions): ?Event { | ||||||||||||||
| $eventExceptions = $event->getExceptions()[0] ?? null; | ||||||||||||||
| $eventDispatcher = $this->eventDispatcher; | ||||||||||||||
|
|
||||||||||||||
| if ($eventExceptions === null) { | ||||||||||||||
| Scope::addGlobalEventProcessor(static function (Event $event) use ($eventDispatcher): ?Event { | ||||||||||||||
|
Check failure on line 20 in src/Integration/UseShopwareExceptionIgnores.php
|
||||||||||||||
| $exceptions = $event->getExceptions(); | ||||||||||||||
| if (empty($exceptions)) { | ||||||||||||||
| return $event; | ||||||||||||||
| } | ||||||||||||||
|
|
||||||||||||||
| $config = $exceptions[$eventExceptions->getType()] ?? []; | ||||||||||||||
|
|
||||||||||||||
| if (!isset($config['log_level'])) { | ||||||||||||||
| return $event; | ||||||||||||||
| } | ||||||||||||||
|
|
||||||||||||||
| if ($config['log_level'] === 'notice') { | ||||||||||||||
| return null; | ||||||||||||||
| } | ||||||||||||||
| $exceptions = $eventDispatcher->dispatch(new FilterExceptionEvent($exceptions))->getExceptions(); | ||||||||||||||
| $event->setExceptions($exceptions); | ||||||||||||||
|
Comment on lines
+25
to
+26
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. 💡 Verification agent 🧩 Analysis chainEnsure type safety when setting exceptions. The static analysis indicates a type mismatch. While the code will work at runtime, it's better to ensure proper typing. The 🏁 Script executed: #!/bin/bash
# Description: Check the return type of FilterExceptionEvent::getExceptions()
# Search for the getExceptions method definition
ast-grep --pattern $'class FilterExceptionEvent {
$$$
public function getExceptions(): $_
$$$
}'Length of output: 103 Let’s locate the actual 🏁 Script executed: #!/bin/bash
# 1. Find where FilterExceptionEvent is defined
rg "class FilterExceptionEvent" -n .
# 2. Find all occurrences of getExceptions to see its return type
rg "function getExceptions" -n .Length of output: 248 Annotate exception array types for static analysis Static analysis warns that • src/Integration/FilterExceptionEvent.php • src/Integration/UseShopwareExceptionIgnores.php Example diff: --- a/src/Integration/FilterExceptionEvent.php
+++ b/src/Integration/FilterExceptionEvent.php
@@
- public function getExceptions(): array
+ /**
+ * @return ExceptionDataBag[]
+ */
+ public function getExceptions(): array
@@
- public function setExceptions(array $exceptions): void
+ /**
+ * @param ExceptionDataBag[] $exceptions
+ */
+ public function setExceptions(array $exceptions): void--- a/src/Integration/UseShopwareExceptionIgnores.php
+++ b/src/Integration/UseShopwareExceptionIgnores.php
@@ -25,6 +25,7 @@
// …
- $exceptions = $eventDispatcher->dispatch(new FilterExceptionEvent($exceptions))->getExceptions();
+ /** @var ExceptionDataBag[] $exceptions */
+ $exceptions = $eventDispatcher->dispatch(new FilterExceptionEvent($exceptions))->getExceptions();
$event->setExceptions($exceptions);📝 Committable suggestion
Suggested change
🧰 Tools🪛 PHPStan (2.1.15)28-28: Parameter #1 $exceptions of method Sentry\Event::setExceptions() expects array<Sentry\ExceptionDataBag>, array given. (argument.type) 🤖 Prompt for AI Agents |
||||||||||||||
|
|
||||||||||||||
| return $event; | ||||||||||||||
| }); | ||||||||||||||
|
|
||||||||||||||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,8 @@ | ||
| sentry: | ||
| options: | ||
| ignore_exceptions: | ||
| - 'Shopware\Storefront\Framework\Routing\Exception\SalesChannelMappingException' | ||
|
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Could be configured in the core as a shopware pull request and would automatically picked up by https://github.com/FriendsOfShopware/shopware-sentry-bundle/blob/main/src/Integration/UseShopwareExceptionIgnores.php ? vendor/shopware/core/Framework/Resources/config/packages/framework.yaml:85 |
||
| - 'Shopware\Core\Framework\Api\Controller\Exception\AuthThrottledException' | ||
| - 'Shopware\Core\Framework\RateLimiter\Exception\RateLimitExceededException' | ||
| - 'Symfony\Component\Console\Exception\CommandNotFoundException' | ||
| - 'League\OAuth2\Server\Exception\OAuthServerException' | ||
|
Comment on lines
+1
to
+8
Member
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Not sure... feels weird to configure a third party bundle here. What do you think?
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Yeah but probably there is no other possibility as we cannot really influence League\OAuth2 ? Sounds legit to me. |
||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,41 @@ | ||
| <?php | ||
|
|
||
| namespace Frosh\SentryBundle\Subscriber; | ||
|
|
||
| use Frosh\SentryBundle\Integration\FilterExceptionEvent; | ||
| use Symfony\Component\EventDispatcher\EventSubscriberInterface; | ||
|
|
||
| class FilterShopwareExceptionIgnoresSubscriber implements EventSubscriberInterface | ||
| { | ||
|
|
||
| public function __construct(private readonly array $shopwareExceptionConfig) | ||
|
Check failure on line 11 in src/Subscriber/FilterShopwareExceptionIgnoresSubscriber.php
|
||
| { | ||
| } | ||
|
|
||
| public static function getSubscribedEvents() | ||
| { | ||
| return [ | ||
| FilterExceptionEvent::class => 'filterSentryExceptions', | ||
| ]; | ||
| } | ||
|
|
||
|
|
||
| public function filterSentryExceptions(FilterExceptionEvent $event): void | ||
| { | ||
| $filteredExceptions = []; | ||
| foreach ($event->getExceptions() as $exception) { | ||
|
|
||
| $exceptionLogLevel = $this->shopwareExceptionConfig[$exception->getType()]['log_level'] ?? null; | ||
|
|
||
| if ($exceptionLogLevel === 'notice') { | ||
| continue; | ||
| } | ||
|
|
||
| $filteredExceptions[] = $exception; | ||
| } | ||
|
|
||
| $event->setExceptions($filteredExceptions); | ||
|
|
||
|
|
||
| } | ||
| } | ||
Uh oh!
There was an error while loading. Please reload this page.