8000 Fix some \Throwable support remaining issues · symfony/symfony@e22ab8d · GitHub
[go: up one dir, main page]

Skip to content

Commit e22ab8d

Browse files
fancywebnicolas-grekas
authored andcommitted
Fix some \Throwable support remaining issues
1 parent 7cee181 commit e22ab8d

File tree

29 files changed

+108
-30
lines changed
  • Profiler
  • Tests/Fixtures/DataCollector
  • Mailer
  • Messenger/DataCollector
  • Translation
  • Validator
  • 29 files changed

    +108
    -30
    lines changed

    src/Symfony/Bridge/Twig/DataCollector/TwigDataCollector.php

    Lines changed: 3 additions & 1 deletion
    Original file line numberDiff line numberDiff line change
    @@ -42,8 +42,10 @@ public function __construct(Profile $profile, Environment $twig = null)
    4242

    4343
    /**
    4444
    * {@inheritdoc}
    45+
    *
    46+
    * @param \Throwable|null $exception
    4547
    */
    46-
    public function collect(Request $request, Response $response, \Exception $exception = null)
    48+
    public function collect(Request $request, Response $response/*, \Throwable $exception = null*/)
    4749
    {
    4850
    }
    4951

    src/Symfony/Bundle/SecurityBundle/DataCollector/SecurityDataCollector.php

    Lines changed: 3 additions & 1 deletion
    Original file line numberDiff line numberDiff line change
    @@ -60,8 +60,10 @@ public function __construct(TokenStorageInterface $tokenStorage = null, RoleHier
    6060

    6161
    /**
    6262
    * {@inheritdoc}
    63+
    *
    64+
    * @param \Throwable|null $exception
    6365
    */
    64-
    public function collect(Request $request, Response $response, \Exception $exception = null)
    66+
    public function collect(Request $request, Response $response/*, \Throwable $exception = null*/)
    6567
    {
    6668
    if (null === $this->tokenStorage) {
    6769
    $this->data = [

    src/Symfony/Component/Cache/DataCollector/CacheDataCollector.php

    Lines changed: 3 additions & 1 deletion
    Original file line numberDiff line numberDiff line change
    @@ -41,8 +41,10 @@ public function addInstance($name, TraceableAdapter $instance)
    4141

    4242
    /**
    4343
    * {@inheritdoc}
    44+
    *
    45+
    * @param \Throwable|null $exception
    4446
    */
    45-
    public function collect(Request $request, Response $response, \Exception $exception = null)
    47+
    public function collect(Request $request, Response $response/*, \Throwable $exception = null*/)
    4648
    {
    4749
    $empty = ['calls' => [], 'config' => [], 'options' => [], 'statistics' => []];
    4850
    $this->data = ['instances' => $empty, 'total' => $empty];

    src/Symfony/Component/Cache/composer.json

    Lines changed: 1 addition & 0 deletions
    Original file line numberDiff line numberDiff line change
    @@ -41,6 +41,7 @@
    4141
    "conflict": {
    4242
    "doctrine/dbal": "<2.5",
    4343
    "symfony/dependency-injection": "<3.4",
    44+
    "symfony/http-kernel": "<4.4",
    4445
    "symfony/var-dumper": "<4.4"
    4546
    },
    4647
    "autoload": {

    src/Symfony/Component/ErrorHandler/Exception/FlattenException.php

    Lines changed: 2 additions & 1 deletion
    Original file line numberDiff line numberDiff line change
    @@ -11,6 +11,7 @@
    1111

    1212
    namespace Symfony\Component\ErrorHandler\Exception;
    1313

    14+
    use Symfony\Component\Debug\Exception\FatalThrowableError;
    1415
    use Symfony\Component\Debug\Exception\FlattenException as LegacyFlattenException;
    1516
    use Symfony\Component\HttpFoundation\Exception\RequestExceptionInterface;
    1617
    use Symfony\Component\HttpFoundation\Response;
    @@ -70,7 +71,7 @@ public static function createFromThrowable(\Throwable $exception, int $statusCod
    7071
    $e->setStatusCode($statusCode);
    7172
    $e->setHeaders($headers);
    7273
    $e->setTraceFromThrowable($exception);
    73-
    $e->setClass(\get_class($exception));
    74+
    $e->setClass($exception instanceof FatalThrowableError ? $exception->getOriginalClassName() : \get_class($exception));
    7475
    $e->setFile($exception->getFile());
    7576
    $e->setLine($exception->getLine());
    7677

    src/Symfony/Component/ErrorHandler/Tests/Exception/FlattenExceptionTest.php

    Lines changed: 14 additions & 0 deletions
    Original file line numberDiff line numberDiff line change
    @@ -12,6 +12,7 @@
    1212
    namespace Symfony\Component\ErrorHandler\Tests\Exception;
    1313

    1414
    use PHPUnit\Framework\TestCase;
    15+
    use Symfony\Component\Debug\Exception\FatalThrowableError;
    1516
    use Symfony\Component\ErrorHandler\Exception\FlattenException;
    1617
    use Symfony\Component\HttpFoundation\Exception\SuspiciousOperationException;
    1718
    use Symfony\Component\HttpKernel\Exception\AccessDeniedHttpException;
    @@ -129,6 +130,19 @@ public function testFlattenHttpException(\Throwable $exception)
    129130
    $this->assertInstanceOf($flattened->getClass(), $exception, 'The class is set to the class of the original exception');
    130131
    }
    131132

    133+
    /**
    134+
    * @group legacy
    135+
    */
    136+
    public function testWrappedThrowable()
    137+
    {
    138+
    $exception = new FatalThrowableError(new \DivisionByZeroError('Ouch', 42));
    139+
    $flattened = FlattenException::create($exception);
    140+
    141+
    $this->assertSame('Ouch', $flattened->getMessage(), 'The message is copied from the original error.');
    142+
    $this->assertSame(42, $flattened->getCode(), 'The code is copied from the original error.');
    143+
    $this->assertSame('DivisionByZeroError', $flattened->getClass(), 'The class is set to the class of the original error');
    144+
    }
    145+
    132146
    public function testThrowable()
    133147
    {
    134148
    $error = new \DivisionByZeroError('Ouch', 42);

    src/Symfony/Component/Form/Extension/DataCollector/FormDataCollector.php

    Lines changed: 5 additions & 1 deletion
    Original file line numberDiff line numberDiff line change
    @@ -80,8 +80,12 @@ public function __construct(FormDataExtractorInterface $dataExtractor)
    8080

    8181
    /**
    8282
    * Does nothing. The data is collected during the form event listeners.
    83+
    *
    84+
    * {@inheritdoc}
    85+
    *
    86+
    * @param \Throwable|null $exception
    8387
    */
    84-
    public function collect(Request $request, Response $response, \Exception $exception = null)
    88+
    public function collect(Request $request, Response $response/*, \Throwable $exception = null*/)
    8589
    {
    8690
    }
    8791

    src/Symfony/Component/Form/composer.json

    Lines changed: 2 additions & 2 deletions
    Original file line numberDiff line numberDiff line change
    @@ -32,7 +32,7 @@
    3232
    "symfony/config": "^3.4|^4.0|^5.0",
    3333
    "symfony/console": "^4.3|^5.0",
    3434
    "symfony/http-foundation": "^3.4|^4.0|^5.0",
    35-
    "symfony/http-kernel": "^4.3",
    35+
    "symfony/http-kernel": "^4.4",
    3636
    "symfony/security-csrf": "^3.4|^4.0|^5.0",
    3737
    "symfony/translation": "^4.2|^5.0",
    3838
    "symfony/var-dumper": "^4.3|^5.0"
    @@ -43,7 +43,7 @@
    4343
    "symfony/dependency-injection": "<3.4",
    4444
    "symfony/doctrine-bridge": "<3.4",
    4545
    "symfony/framework-bundle": "<3.4",
    46-
    "symfony/http-kernel": "<4.3",
    46+
    "symfony/http-kernel": "<4.4",
    4747
    "symfony/intl": "<4.3",
    4848
    "symfony/translation": "<4.2",
    4949
    "symfony/twig-bridge": "<3.4.5|<4.0.5,>=4.0"

    src/Symfony/Component/HttpClient/DataCollector/HttpClientDataCollector.php

    Lines changed: 3 additions & 1 deletion
    Original file line numberDiff line numberDiff line change
    @@ -33,8 +33,10 @@ public function registerClient(string $name, TraceableHttpClient $client)
    3333

    3434
    /**
    3535
    * {@inheritdoc}
    36+
    *
    37+
    * @param \Throwable|null $exception
    3638
    */
    37-
    public function collect(Request $request, Response $response, \Exception $exception = null)
    39+
    public function collect(Request $request, Response $response/*, \Throwable $exception = null*/)
    3840
    {
    3941
    $this->initData();
    4042

    src/Symfony/Component/HttpClient/composer.json

    Lines changed: 4 additions & 1 deletion
    Original file line numberDiff line numberDiff line change
    @@ -31,11 +31,14 @@
    3131
    "php-http/httplug": "^1.0|^2.0",
    3232
    "psr/http-client": "^1.0",
    3333
    "symfony/dependency-injection": "^4.3|^5.0",
    34-
    "symfony/http-kernel": "^4.3",
    34+
    "symfony/http-kernel": "^4.4",
    3535
    "symfony/process": "^4.2|^5.0",
    3636
    "symfony/service-contracts": "^1.0|^2",
    3737
    "symfony/var-dumper": "^4.3|^5.0"
    3838
    },
    39+
    "conflict": {
    40+
    "symfony/http-kernel": "<4.4"
    41+
    },
    3942
    "autoload": {
    4043
    "psr-4": { "Symfony\\Component\\HttpClient\\": "" },
    4144
    "exclude-from-classmap": [

    src/Symfony/Component/HttpKernel/DataCollector/AjaxDataCollector.php

    Lines changed: 6 additions & 1 deletion
    Original file line numberDiff line numberDiff line change
    @@ -23,7 +23,12 @@
    2323
    */
    2424
    class AjaxDataCollector extends DataCollector
    2525
    {
    26-
    public function collect(Request $request, Response $response, \Exception $exception = null)
    26+
    /**
    27+
    * {@inheritdoc}
    28+
    *
    29+
    * @param \Throwable|null $exception
    30+
    */
    31+
    public function collect(Request $request, Response $response/*, \Throwable $exception = null*/)
    2732
    {
    2833
    // all collecting is done client side
    2934
    }

    src/Symfony/Component/HttpKernel/DataCollector/ConfigDataCollector.php

    Lines changed: 3 additions & 1 deletion
    Original file line numberDiff line numberDiff line change
    @@ -56,8 +56,10 @@ public function setKernel(KernelInterface $kernel = null)
    5656

    5757
    /**
    5858
    * {@inheritdoc}
    59+
    *
    60+
    * @param \Throwable|null $exception
    5961
    */
    60-
    public function collect(Request $request, Response $response, \Exception $exception = null)
    62+
    public function collect(Request $request, Response $response/*, \Throwable $exception = null*/)
    6163
    {
    6264
    $this->data = [
    6365
    'app_name' => $this->name,

    src/Symfony/Component/HttpKernel/DataCollector/DumpDataCollector.php

    Lines changed: 6 additions & 1 deletion
    Original file line numberDiff line numberDiff line change
    @@ -98,7 +98,12 @@ public function dump(Data $data)
    9898
    }
    9999
    }
    100100

    101-
    public function collect(Request $request, Response $response, \Exception $exception = null)
    101+
    /**
    102+
    * {@inheritdoc}
    103+
    *
    104+
    * @param \Throwable|null $exception
    105+
    */
    106+
    public function collect(Request $request, Response $response/*, \Throwable $exception = null*/)
    102107
    {
    103108
    if (!$this->dataCount) {
    104109
    $this->data = [];

    src/Symfony/Component/HttpKernel/DataCollector/EventDataCollector.php

    Lines changed: 3 additions & 1 deletion
    Original file line numberDiff line numberDiff line change
    @@ -40,8 +40,10 @@ public function __construct(EventDispatcherInterface $dispatcher = null, Request
    4040

    4141
    /**
    4242
    * {@inheritdoc}
    43+
    *
    44+
    * @param \Throwable|null $exception
    4345
    */
    44-
    public function collect(Request $request, Response $response, \Exception $exception = null)
    46+
    public function collect(Request $request, Response $response/*, \Throwable $exception = null*/)
    4547
    {
    4648
    $this->currentRequest = $this->requestStack && $this->requestStack->getMasterRequest() !== $request ? $request : null;
    4749
    $this->data = [

    src/Symfony/Component/HttpKernel/DataCollector/ExceptionDataCollector.php

    Lines changed: 5 additions & 1 deletion
    Original file line numberDiff line numberDiff line change
    @@ -26,9 +26,13 @@ class ExceptionDataCollector extends DataCollector
    2626
    {
    2727
    /**
    2828
    * {@inheritdoc}
    29+
    *
    30+
    * @param \Throwable|null $exception
    2931
    */
    30-
    public function collect(Request $request, Response $response, \Exception $exception = null)
    32+
    public function collect(Request $request, Response $response/*, \Throwable $exception = null*/)
    3133
    {
    34+
    $exception = 2 < \func_num_args() ? func_get_arg(2) : null;
    35+
    3236
    if (null !== $exception) {
    3337
    $this->data = [
    3438
    'exception' => FlattenException::createFromThrowable($exception),

    src/Symfony/Component/HttpKernel/DataCollector/LoggerDataCollector.php

    Lines changed: 3 additions & 1 deletion
    Original file line numberDiff line numberDiff line change
    @@ -43,8 +43,10 @@ public function __construct($logger = null, string $containerPathPrefix = null,
    4343

    4444
    /**
    4545
    * {@inheritdoc}
    46+
    *
    47+
    * @param \Throwable|null $exception
    4648
    */
    47-
    public function collect(Request $request, Response $response, \Exception $exception = null)
    49+
    public function collect(Request $request, Response $response/*, \Throwable $exception = null*/)
    4850
    {
    4951
    $this->currentRequest = $this->requestStack && $this->requestStack->getMasterRequest() !== $request ? $request : null;
    5052
    }

    src/Symfony/Component/HttpKernel/DataCollector/MemoryDataCollector.php

    Lines changed: 3 additions & 1 deletion
    Original file line numberDiff line numberDiff line change
    @@ -30,8 +30,10 @@ public function __construct()
    3030

    3131
    /**
    3232
    * {@inheritdoc}
    33+
    *
    34+
    * @param \Throwable|null $exception
    3335
    */
    34-
    public function collect(Request $request, Response $response, \Exception $exception = null)
    36+
    public function collect(Request $request, Response $response/*, \Throwable $exception = null*/)
    3537
    {
    3638
    $this->updateMemoryUsage();
    3739
    }

    src/Symfony/Component/HttpKernel/DataCollector/RequestDataCollector.php

    Lines changed: 3 additions & 1 deletion
    Original file line numberDiff line numberDiff line change
    @@ -36,8 +36,10 @@ public function __construct()
    3636

    3737
    /**
    3838
    * {@inheritdoc}
    39+
    *
    40+
    * @param \Throwable|null $exception
    3941
    */
    40-
    public function collect(Request $request, Response $response, \Exception $exception = null)
    42+
    public function collect(Request $request, Response $response/*, \Throwable $exception = null*/)
    4143
    {
    4244
    // attributes are serialized and as they can be anything, they need to be converted to strings.
    4345
    $attributes = [];

    src/Symfony/Component/HttpKernel/DataCollector/RouterDataCollector.php

    Lines changed: 3 additions & 1 deletion
    Original file line numberDiff line numberDiff line change
    @@ -34,9 +34,11 @@ public function __construct()
    3434
    /**
    3535
    * {@inheritdoc}
    3636
    *
    37+
    * @param \Throwable|null $exception
    38+
    *
    3739
    * @final since Symfony 4.4
    3840
    */
    39-
    public function collect(Request $request, Response $response, \Exception $exception = null)
    41+
    public function collect(Request $request, Response $response/*, \Throwable $exception = null*/)
    4042
    {
    4143
    if ($response instanceof RedirectResponse) {
    4244
    $this->data['redirect'] = true;

    src/Symfony/Component/HttpKernel/DataCollector/TimeDataCollector.php

    Lines changed: 3 additions & 1 deletion
    Original file line numberDiff line numberDiff line change
    @@ -35,8 +35,10 @@ public function __construct(KernelInterface $kernel = null, Stopwatch $stopwatch
    3535

    3636
    /**
    3737
    * {@inheritdoc}
    38+
    *
    39+
    * @param \Throwable|null $exception
    3840
    */
    39-
    public function collect(Request $request, Response $response, \Exception $exception = null)
    41+
    public function collect(Request $request, Response $response/*, \Throwable $exception = null*/)
    4042
    {
    4143
    if (null !== $this->kernel) {
    4244
    $startTime = $this->kernel->getStartTime();

    src/Symfony/Component/HttpKernel/Profiler/Profiler.php

    Lines changed: 7 additions & 1 deletion
    Original file line numberDiff line numberDiff line change
    @@ -12,6 +12,7 @@
    1212
    namespace Symfony\Component\HttpKernel\Profiler;
    1313

    1414
    use Psr\Log\LoggerInterface;
    15+
    use Symfony\Component\Debug\Exception\FatalThrowableError;
    1516
    use Symfony\Component\HttpFoundation\Exception\ConflictingHeadersException;
    1617
    use Symfony\Component\HttpFoundation\Request;
    1718
    use Symfony\Component\HttpFoundation\Response;
    @@ -167,9 +168,14 @@ public function collect(Request $request, Response $response/*, \Throwable $exce
    167168

    168169
    $response->headers->set('X-Debug-Token', $profile->getToken());
    169170

    171+
    $wrappedException = null;
    170172
    foreach ($this->collectors as $collector) {
    171-
    $collector->collect($request, $response, $exception);
    173+
    if (($e = $exception) instanceof \Error) {
    174+
    $r = new \ReflectionMethod($collector, 'collect');
    175+
    $e = 2 >= $r->getNumberOfParameters() || !($p = $r->getParameters()[2])->hasType() || \Exception::class !== $p->getType()->getName() ? $e : ($wrappedException ?? $wrappedException = new FatalThrowableError($e));
    176+
    }
    172177

    178+
    $collector->collect($request, $response, $e);
    173179
    // we need to clone for sub-requests
    174180
    $profile->addCollector(clone $collector);
    175181
    }

    src/Symfony/Component/HttpKernel/Tests/Fixtures/DataCollector/CloneVarDataCollector.php

    Lines changed: 6 additions & 1 deletion
    Original file line numberDiff line numberDiff line change
    @@ -24,7 +24,12 @@ public function __construct($varToClone)
    2424
    $this->varToClone = $varToClone;
    2525
    }
    2626

    27-
    public function collect(Request $request, Response $response, \Exception $exception = null)
    27+
    /**
    28+
    * {@inheritdoc}
    29+
    *
    30+
    * @param \Throwable|null $exception
    31+
    */
    32+
    public function collect(Request $request, Response $response/*, \Throwable $exception = null*/)
    2833
    {
    2934
    $this->data = $this->cloneVar($this->varToClone);
    3035
    }

    src/Symfony/Component/Mailer/DataCollector/MessageDataCollector.php

    Lines changed: 3 additions & 1 deletion
    Original file line numberDiff line numberDiff line change
    @@ -31,8 +31,10 @@ public function __construct(MessageLoggerListener $logger)
    3131

    3232
    /**
    3333
    * {@inheritdoc}
    34+
    *
    35+
    * @param \Throwable|null $exception
    3436
    */
    35-
    public function collect(Request $request, Response $response, \Exception $exception = null)
    37+
    public function collect(Request $request, Response $response/*, \Throwable $exception = null*/)
    3638
    {
    3739
    $this->data['events'] = $this->events;
    3840
    }

    src/Symfony/Component/Mailer/composer.json

    Lines changed: 1 addition & 0 deletions
    Original file line numberDiff line numberDiff line change
    @@ -34,6 +34,7 @@
    3434
    "symfony/sendgrid-mailer": "^4.4|^5.0"
    3535
    },
    3636
    "conflict": {
    37+
    "symfony/http-kernel": "<4.4",
    3738
    "symfony/sendgrid-mailer": "<4.4"
    3839
    },
    3940
    "autoload": {

    src/Symfony/Component/Messenger/DataCollector/MessengerDataCollector.php

    Lines changed: 3 additions & 1 deletion
    Original file line numberDiff line numberDiff line change
    @@ -34,8 +34,10 @@ public function registerBus(string $name, TraceableMessageBus $bus)
    3434

    3535
    /**
    3636
    * {@inheritdoc}
    37+
    *
    38+
    * @param \Throwable|null $exception
    3739
    */
    38-
    public function collect(Request $request, Response $response, \Exception $exception = null)
    40+
    public function collect(Request $request, Response $response/*, \Throwable $exception = null*/)
    3941
    {
    4042
    // Noop. Everything is collected live by the traceable buses & cloned as late as possible.
    4143
    }

    src/Symfony/Component/Translation/DataCollector/TranslationDataCollector.php

    Lines changed: 3 additions & 1 deletion
    Original file line numberDiff line numberDiff line change
    @@ -46,8 +46,10 @@ public function lateCollect()
    4646

    4747
    /**
    4848
    * {@inheritdoc}
    49+
    *
    50+
    * @param \Throwable|null $exception
    4951
    */
    50-
    public function collect(Request $request, Response $response, \Exception $exception = null)
    52+
    public function collect(Request $request, Response $response/*, \Throwable $exception = null*/)
    5153
    {
    5254
    $this->data['locale'] = $this->translator->getLocale();
    5355
    $this->data['fallback_locales'] = $this->translator->getFallbackLocales();

    src/Symfony/Component/Translation/composer.json

    Lines changed: 2 additions & 2 deletions
    Original file line numberDiff line numberDiff line change
    @@ -24,17 +24,17 @@
    2424
    "symfony/config": "^3.4|^4.0|^5.0",
    2525
    "symfony/console": "^3.4|^4.0|^5.0",
    2626
    "symfony/dependency-injection": "^3.4|^4.0|^5.0",
    27-
    "symfony/http-kernel": "^3.4|^4.0",
    27+
    "symfony/http-kernel": "^4.4",
    2828
    "symfony/intl": "^3.4|^4.0|^5.0",
    2929
    "symfony/service-contracts": "^1.1.2|^2",
    30-
    "symfony/var-dumper": "^3.4|^4.0|^5.0",
    3130
    "symfony/yaml": "^3.4|^4.0|^5.0",
    3231
    "symfony/finder": "~2.8|~3.0|~4.0|^5.0",
    3332
    "psr/log": "~1.0"
    3433
    },
    3534
    "conflict": {
    3635
    "symfony/config": "<3.4",
    3736
    "symfony/dependency-injection": "<3.4",
    37+
    "symfony/http-kernel": "<4.4",
    3838
    "symfony/yaml": "<3.4"
    3939
    },
    4040
    "provide": {

    src/Symfony/Component/Validator/DataCollector/ValidatorDataCollector.php

    Lines changed: 3 additions & 1 deletion
    Original file line numberDiff line numberDiff line change
    @@ -39,8 +39,10 @@ public function __construct(TraceableValidator $validator)
    3939

    4040
    /**
    4141
    * {@inheritdoc}
    42+
    *
    43+
    * @param \Throwable|null $exception
    4244
    */
    43-
    public function collect(Request $request, Response $response, \Exception $exception = null)
    45+
    public function collect(Request $request, Response $response/*, \Throwable $exception = null*/)
    4446
    {
    4547
    // Everything is collected once, on kernel terminate.
    4648
    }

    0 commit comments

    Comments
     (0)
    0