8000 Fix some \Throwable support remaining issues by fancyweb · Pull Request #34336 · symfony/symfony · GitHub
[go: up one dir, main page]

Skip to content

Fix some \Throwable support remaining issues #34336

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

Merged
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 3 additions & 1 deletion src/Symfony/Bridge/Twig/DataCollector/TwigDataCollector.php
Original file line number Diff line number Diff line change
Expand Up @@ -42,8 +42,10 @@ public function __construct(Profile $profile, Environment $twig = null)

/**
* {@inheritdoc}
*
* @param \Throwable|null $exception
*/
public function collect(Request $request, Response $response, \Exception $exception = null)
public function collect(Request $request, Response $response/*, \Throwable $exception = null*/)
{
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -60,8 +60,10 @@ public function __construct(TokenStorageInterface $tokenStorage = null, RoleHier

/**
* {@inheritdoc}
*
* @param \Throwable|null $exception
*/
public function collect(Request $request, Response $response, \Exception $exception = null)
public function collect(Request $request, Response $response/*, \Throwable $exception = null*/)
{
if (null === $this->tokenStorage) {
$this->data = [
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -41,8 +41,10 @@ public function addInstance($name, TraceableAdapter $instance)

/**
* {@inheritdoc}
*
* @param \Throwable|null $exception
*/
public function collect(Request $request, Response $response, \Exception $exception = null)
public function collect(Request $request, Response $response/*, \Throwable $exception = null*/)
{
$empty = ['calls' => [], 'config' => [], 'options' => [], 'statistics' => []];
$this->data = ['instances' => $empty, 'total' => $empty];
Expand Down
1 change: 1 addition & 0 deletions src/Symfony/Component/Cache/composer.json
Original file line number Diff line number Diff line change
Expand Up @@ -41,6 +41,7 @@
"conflict": {
"doctrine/dbal": "<2.5",
"symfony/dependency-injection": "<3.4",
"symfony/http-kernel": "<4.4",
"symfony/var-dumper": "<4.4"
},
"autoload": {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@

namespace Symfony\Component\ErrorHandler\Exception;

use Symfony\Component\Debug\Exception\FatalThrowableError;
use Symfony\Component\Debug\Exception\FlattenException as LegacyFlattenException;
use Symfony\Component\HttpFoundation\Exception\RequestExceptionInterface;
use Symfony\Component\HttpFoundation\Response;
Expand Down Expand Up @@ -70,7 +71,7 @@ public static function createFromThrowable(\Throwable $exception, int $statusCod
$e->setStatusCode($statusCode);
$e->setHeaders($headers);
$e->setTraceFromThrowable($exception);
$e->setClass(\get_class($exception));
$e->setClass($exception instanceof FatalThrowableError ? $exception->getOriginalClassName() : \get_class($exception));
$e->setFile($exception->getFile());
$e->setLine($exception->getLine());

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@
namespace Symfony\Component\ErrorHandler\Tests\Exception;

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

/**
* @group legacy
*/
public function testWrappedThrowable()
{
$exception = new FatalThrowableError(new \DivisionByZeroError('Ouch', 42));
$flattened = FlattenException::create($exception);

$this->assertSame('Ouch', $flattened->getMessage(), 'The message is copied from the original error.');
$this->assertSame(42, $flattened->getCode(), 'The code is copied from the original error.');
$this->assertSame('DivisionByZeroError', $flattened->getClass(), 'The class is set to the class of the original error');
}

public function testThrowable()
{
$error = new \DivisionByZeroError('Ouch', 42);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -80,8 +80,12 @@ public function __construct(FormDataExtractorInterface $dataExtractor)

/**
* Does nothing. The data is collected during the form event listeners.
*
* {@inheritdoc}
*
* @param \Throwable|null $exception
*/
public function collect(Request $request, Response $response, \Exception $exception = null)
public function collect(Request $request, Response $response/*, \Throwable $exception = null*/)
{
}

Expand Down
4 changes: 2 additions & 2 deletions src/Symfony/Component/Form/composer.json
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,7 @@
"symfony/config": "^3.4|^4.0|^5.0",
"symfony/console": "^4.3|^5.0",
"symfony/http-foundation": "^3.4|^4.0|^5.0",
"symfony/http-kernel": "^4.3",
"symfony/http-kernel": "^4.4",
"symfony/security-csrf": "^3.4|^4.0|^5.0",
"symfony/translation": "^4.2|^5.0",
"symfony/var-dumper": "^4.3|^5.0"
Expand All @@ -43,7 +43,7 @@
"symfony/dependency-injection": "<3.4",
"symfony/doctrine-bridge": "<3.4",
"symfony/framework-bundle": "<3.4",
"symfony/http-kernel": "<4.3",
"symfony/http-kernel": "<4.4",
"symfony/intl": "<4.3",
"symfony/translation": "<4.2",
"symfony/twig-bridge": "<3.4.5|<4.0.5,>=4.0"
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -33,8 +33,10 @@ public function registerClient(string $name, TraceableHttpClient $client)

/**
* {@inheritdoc}
*
* @param \Throwable|null $exception
*/
public function collect(Request $request, Response $response, \Exception $exception = null)
public function collect(Request $request, Response $response/*, \Throwable $exception = null*/)
{
$this->initData();

Expand Down
8 changes: 5 additions & 3 deletions src/Symfony/Component/HttpClient/composer.json
Original file line number Diff line number Diff line change
Expand Up @@ -31,10 +31,12 @@
"php-http/httplug": "^1.0|^2.0",
"psr/http-client": "^1.0",
"symfony/dependency-injection": "^4.3|^5.0",
"symfony/http-kernel": "^4.3",
"symfony/http-kernel": "^4.4",
"symfony/process": "^4.2|^5.0",
"symfony/service-contracts": "^1.0|^2",
"symfony/var-dumper": "^4.3|^5.0"
"symfony/service-contracts": "^1.0|^2"
},
"conflict": {
"symfony/http-kernel": "<4.4"
},
"autoload": {
"psr-4": { "Symfony\\Component\\HttpClient\\": "" },
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,12 @@
*/
class AjaxDataCollector extends DataCollector
{
public function collect(Request $request, Response $response, \Exception $exception = null)
/**
* {@inheritdoc}
*
* @param \Throwable|null $exception
*/
public function collect(Request $request, Response $response/*, \Throwable $exception = null*/)
{
// all collecting is done client side
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -56,8 +56,10 @@ public function setKernel(KernelInterface $kernel = null)

/**
* {@inheritdoc}
*
* @param \Throwable|null $exception
*/
public function collect(Request $request, Response $response, \Exception $exception = null)
public function collect(Request $request, Response $response/*, \Throwable $exception = null*/)
{
$this->data = [
'app_name' => $this->name,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -98,7 +98,12 @@ public function dump(Data $data)
}
}

public function collect(Request $request, Response $response, \Exception $exception = null)
/**
* {@inheritdoc}
*
* @param \Throwable|null $exception
*/
public function collect(Request $request, Response $response/*, \Throwable $exception = null*/)
{
if (!$this->dataCount) {
$this->data = [];
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -40,8 +40,10 @@ public function __construct(EventDispatcherInterface $dispatcher = null, Request

/**
* {@inheritdoc}
*
* @param \Throwable|null $exception
*/
public function collect(Request $request, Response $response, \Exception $exception = null)
public function collect(Request $request, Response $response/*, \Throwable $exception = null*/)
{
$this->currentRequest = $this->requestStack && $this->requestStack->getMasterRequest() !== $request ? $request : null;
$this->data = [
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -26,9 +26,13 @@ class ExceptionDataCollector extends DataCollector
{
/**
* {@inheritdoc}
*
* @param \Throwable|null $exception
*/
public function collect(Request $request, Response $response, \Exception $exception = null)
public function collect(Request $request, Response $response/*, \Throwable $exception = null*/)
{
$exception = 2 < \func_num_args() ? func_get_arg(2) : null;

if (null !== $exception) {
$this->data = [
'exception' => FlattenException::createFromThrowable($exception),
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -43,8 +43,10 @@ public function __construct($logger = null, string $containerPathPrefix = null,

/**
* {@inheritdoc}
*
* @param \Throwable|null $exception
*/
public function collect(Request $request, Response $response, \Exception $exception = null)
public function collect(Request $request, Response $response/*, \Throwable $exception = null*/)
{
$this->currentRequest = $this->requestStack && $this->requestStack->getMasterRequest() !== $request ? $request : null;
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -30,8 +30,10 @@ public function __construct()

/**
* {@inheritdoc}
*
* @param \Throwable|null $exception
*/
public function collect(Request $request, Response $response, \Exception $exception = null)
public function collect(Request $request, Response $response/*, \Throwable $exception = null*/)
{
$this->updateMemoryUsage();
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -36,8 +36,10 @@ public function __construct()

/**
* {@inheritdoc}
*
* @param \Throwable|null $exception
*/
public function collect(Request $request, Response $response, \Exception $exception = null)
public function collect(Request $request, Response $response/*, \Throwable $exception = null*/)
{
// attributes are serialized and as they can be anything, they need to be converted to strings.
$attributes = [];
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -34,9 +34,11 @@ public function __construct()
/**
* {@inheritdoc}
*
* @param \Throwable|null $exception
*
* @final since Symfony 4.4
*/
public function collect(Request $request, Response $response, \Exception $exception = null)
public function collect(Request $request, Response $response/*, \Throwable $exception = null*/)
{
if ($response instanceof RedirectResponse) {
$this->data['redirect'] = true;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -35,8 +35,10 @@ public function __construct(KernelInterface $kernel = null, Stopwatch $stopwatch

/**
* {@inheritdoc}
*
* @param \Throwable|null $exception
*/
public function collect(Request $request, Response $response, \Exception $exception = null)
public function collect(Request $request, Response $response/*, \Throwable $exception = null*/)
{
if (null !== $this->kernel) {
$startTime = $this->kernel->getStartTime();
Expand Down
8 changes: 7 additions & 1 deletion src/Symfony/Component/HttpKernel/Profiler/Profiler.php
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@
namespace Symfony\Component\HttpKernel\Profiler;

use Psr\Log\LoggerInterface;
use Symfony\Component\Debug\Exception\FatalThrowableError;
use Symfony\Component\HttpFoundation\Exception\ConflictingHeadersException;
use Symfony\Component\HttpFoundation\Request;
use Symfony\Component\HttpFoundation\Response;
Expand Down Expand Up @@ -167,9 +168,14 @@ public function collect(Request $request, Response $response/*, \Throwable $exce

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

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

$collector->collect($request, $response, $e);
// we need to clone for sub-requests
$profile->addCollector(clone $collector);
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,12 @@ public function __construct($varToClone)
$this->varToClone = $varToClone;
}

public function collect(Request $request, Response $response, \Exception $exception = null)
/**
* {@inheritdoc}
*
* @param \Throwable|null $exception
*/
public function collect(Request $request, Response $response/*, \Throwable $exception = null*/)
{
$this->data = $this->cloneVar($this->varToClone);
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -31,8 +31,10 @@ public function __construct(MessageLoggerListener $logger)

/**
* {@inheritdoc}
*
* @param \Throwable|null $exception
*/
public function collect(Request $request, Response $response, \Exception $exception = null)
public function collect(Request $request, Response $response/*, \Throwable $exception = null*/)
{
$this->data['events'] = $this->events;
}
Expand Down
1 change: 1 addition & 0 deletions src/Symfony/Component/Mailer/composer.json
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,7 @@
"symfony/sendgrid-mailer": "^4.4|^5.0"
},
"conflict": {
"symfony/http-kernel": "<4.4",
"symfony/sendgrid-mailer": "<4.4"
},
"autoload": {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -34,8 +34,10 @@ public function registerBus(string $name, TraceableMessageBus $bus)

/**
* {@inheritdoc}
*
* @param \Throwable|null $exception
*/
publi 37CA c function collect(Request $request, Response $response, \Exception $exception = null)
public function collect(Request $request, Response $response/*, \Throwable $exception = null*/)
{
// Noop. Everything is collected live by the traceable buses & cloned as late as possible.
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -46,8 +46,10 @@ public function lateCollect()

/**
* {@inheritdoc}
*
* @param \Throwable|null $exception
*/
public function collect(Request $request, Response $response, \Exception $exception = null)
public function collect(Request $request, Response $response/*, \Throwable $exception = null*/)
{
$this->data['locale'] = $this->translator->getLocale();
$this->data['fallback_locales'] = $this->translator->getFallbackLocales();
Expand Down
4 changes: 2 additions & 2 deletions src/Symfony/Component/Translation/composer.json
Original file line number Diff line number Diff line change
Expand Up @@ -24,17 +24,17 @@
"symfony/config": "^3.4|^4.0|^5.0",
"symfony/console": "^3.4|^4.0|^5.0",
"symfony/dependency-injection": "^3.4|^4.0|^5.0",
"symfony/http-kernel": "^3.4|^4.0",
"symfony/http-kernel": "^4.4",
"symfony/intl": "^3.4|^4.0|^5.0",
"symfony/service-contracts": "^1.1.2|^2",
"symfony/var-dumper": "^3.4|^4.0|^5.0",
"symfony/yaml": "^3.4|^4.0|^5.0",
"symfony/finder": "~2.8|~3.0|~4.0|^5.0",
"psr/log": "~1.0"
},
"conflict": {
"symfony/config": "<3.4",
"symfony/dependency-injection": "<3.4",
"symfony/http-kernel": "<4.4",
"symfony/yaml": "<3.4"
},
"provide": {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -39,8 +39,10 @@ public function __construct(TraceableValidator $validator)

/**
* {@inheritdoc}
*
* @param \Throwable|null $exception
*/
public function collect(Request $request, Response $response, \Exception $exception = null)
public function collect(Request $request, Response $response/*, \Throwable $exception = null*/)
{
// Everything is collected once, on kernel terminate.
}
Expand Down
Loading
0