Skip to content

Commit

Permalink
Fix fatal errors logged twice on Symfony 3.4 on PHP 7.3 and 7.4 (
Browse files Browse the repository at this point in the history
  • Loading branch information
ste93cry committed Oct 25, 2021
1 parent cbd486c commit 241fc0c
Show file tree
Hide file tree
Showing 5 changed files with 36 additions and 3 deletions.
2 changes: 2 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,8 @@

## Unreleased

- Fix fatal errors logged twice on Symfony `3.4` (#570)

## 4.2.4 (2021-10-20)

- Add return typehints to the methods of the `SentryExtension` class to prepare for Symfony 6 (#563)
Expand Down
10 changes: 10 additions & 0 deletions phpstan-baseline.neon
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,11 @@ parameters:
count: 1
path: src/DependencyInjection/Configuration.php

-
message: "#^Class Symfony\\\\Component\\\\Debug\\\\Exception\\\\FatalErrorException not found\\.$#"
count: 1
path: src/DependencyInjection/SentryExtension.php

-
message: "#^Else branch is unreachable because previous condition is always true\\.$#"
count: 1
Expand Down Expand Up @@ -55,6 +60,11 @@ parameters:
count: 1
path: src/Tracing/Doctrine/DBAL/TracingServerInfoAwareDriverConnection.php

-
message: "#^Class Symfony\\\\Component\\\\Debug\\\\Exception\\\\FatalErrorException not found\\.$#"
count: 1
path: tests/DependencyInjection/SentryExtensionTest.php

-
message: "#^Class Symfony\\\\Bundle\\\\FrameworkBundle\\\\Client not found\\.$#"
count: 1
Expand Down
7 changes: 6 additions & 1 deletion psalm-baseline.xml
Original file line number Diff line number Diff line change
@@ -1,5 +1,10 @@
<?xml version="1.0" encoding="UTF-8"?>
<files psalm-version="4.10.0@916b098b008f6de4543892b1e0651c1c3b92cbfa">
<files psalm-version="4.11.1@e33492398bd4e5e2ab60e331d445979bd83feecd">
<file src="src/DependencyInjection/SentryExtension.php">
<UndefinedClass occurrences="1">
<code>FatalErrorException</code>
</UndefinedClass>
</file>
<file src="src/EventListener/ConsoleCommandListener.php">
<InvalidExtendClass occurrences="1">
<code>ConsoleListener</code>
Expand Down
10 changes: 9 additions & 1 deletion src/DependencyInjection/SentryExtension.php
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,7 @@
use Symfony\Bundle\TwigBundle\TwigBundle;
use Symfony\Component\Cache\CacheItem;
use Symfony\Component\Config\FileLocator;
use Symfony\Component\Debug\Exception\FatalErrorException;
use Symfony\Component\DependencyInjection\ContainerBuilder;
use Symfony\Component\DependencyInjection\Definition;
use Symfony\Component\DependencyInjection\Loader;
Expand Down Expand Up @@ -273,7 +274,14 @@ private function configureErrorListenerIntegration(array $integrations, bool $re
// Prepend this integration to the beginning of the array so that
// we can save some performance by skipping the rest of the integrations
// if the error must be ignored
array_unshift($integrations, new Definition(IgnoreErrorsIntegration::class, [['ignore_exceptions' => [FatalError::class]]]));
array_unshift($integrations, new Definition(IgnoreErrorsIntegration::class, [
[
'ignore_exceptions' => [
FatalError::class,
FatalErrorException::class,
],
],
]));
}

return $integrations;
Expand Down
10 changes: 9 additions & 1 deletion tests/DependencyInjection/SentryExtensionTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,7 @@
use Sentry\Transport\TransportFactoryInterface;
use Symfony\Bundle\TwigBundle\TwigBundle;
use Symfony\Component\Console\ConsoleEvents;
use Symfony\Component\Debug\Exception\FatalErrorException;
use Symfony\Component\DependencyInjection\ContainerBuilder;
use Symfony\Component\DependencyInjection\Definition;
use Symfony\Component\DependencyInjection\ParameterBag\EnvPlaceholderParameterBag;
Expand Down Expand Up @@ -185,7 +186,14 @@ public function testClientIsCreatedFromOptions(): void
$optionsDefinition = $container->getDefinition('sentry.client.options');
$expectedOptions = [
'integrations' => [
new Definition(IgnoreErrorsIntegration::class, [['ignore_exceptions' => [FatalError::class]]]),
new Definition(IgnoreErrorsIntegration::class, [
[
'ignore_exceptions' => [
FatalError::class,
FatalErrorException::class,
],
],
]),
new Reference('App\\Sentry\\Integration\\FooIntegration'),
],
'default_integrations' => false,
Expand Down

0 comments on commit 241fc0c

Please sign in to comment.