Skip to content

Commit a4c93a6

Browse files
committed
[ErrorHandler] Rework fatal error handlers
1 parent b829439 commit a4c93a6

37 files changed

+545
-631
lines changed

src/Symfony/Bundle/FrameworkBundle/Console/Application.php

+2-2
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,7 @@
2020
use Symfony\Component\Console\Output\OutputInterface;
2121
use Symfony\Component\Console\Style\SymfonyStyle;
2222
use Symfony\Component\DependencyInjection\ContainerAwareInterface;
23-
use Symfony\Component\ErrorHandler\Exception\FatalThrowableError;
23+
use Symfony\Component\ErrorHandler\Exception\ErrorException;
2424
use Symfony\Component\HttpKernel\Bundle\Bundle;
2525
use Symfony\Component\HttpKernel\Kernel;
2626
use Symfony\Component\HttpKernel\KernelInterface;
@@ -208,7 +208,7 @@ private function renderRegistrationErrors(InputInterface $input, OutputInterface
208208

209209
foreach ($this->registrationErrors as $error) {
210210
if (!$error instanceof \Exception) {
211-
$error = new FatalThrowableError($error);
211+
$error = new ErrorException($error);
212212
}
213213

214214
$this->doRenderException($error, $output);

src/Symfony/Component/Console/Application.php

+2-2
Original file line numberDiff line numberDiff line change
@@ -44,7 +44,7 @@
4444
use Symfony\Component\Debug\ErrorHandler as LegacyErrorHandler;
4545
use Symfony\Component\Debug\Exception\FatalThrowableError as LegacyFatalThrowableError;
4646
use Symfony\Component\ErrorHandler\ErrorHandler;
47-
use Symfony\Component\ErrorHandler\Exception\FatalThrowableError;
47+
use Symfony\Component\ErrorHandler\Exception\ErrorException;
4848
use Symfony\Component\EventDispatcher\EventDispatcherInterface;
4949
use Symfony\Component\EventDispatcher\LegacyEventDispatcherProxy;
5050
use Symfony\Contracts\Service\ResetInterface;
@@ -129,7 +129,7 @@ public function run(InputInterface $input = null, OutputInterface $output = null
129129

130130
$renderException = function (\Throwable $e) use ($output) {
131131
if (!$e instanceof \Exception) {
132-
$e = class_exists(FatalThrowableError::class) ? new FatalThrowableError($e) : (class_exists(LegacyFatalThrowableError::class) ? new LegacyFatalThrowableError($e) : new \ErrorException($e->getMessage(), $e->getCode(), E_ERROR, $e->getFile(), $e->getLine()));
132+
$e = class_exists(ErrorException::class) ? new ErrorException($e) : (class_exists(LegacyFatalThrowableError::class) ? new LegacyFatalThrowableError($e) : new \ErrorException($e->getMessage(), $e->getCode(), E_ERROR, $e->getFile(), $e->getLine()));
133133
}
134134
if ($output instanceof ConsoleOutputInterface) {
135135
$this->renderException($e, $output->getErrorOutput());

src/Symfony/Component/Debug/Exception/ClassNotFoundException.php

+2-2
Original file line numberDiff line numberDiff line change
@@ -11,14 +11,14 @@
1111

1212
namespace Symfony\Component\Debug\Exception;
1313

14-
@trigger_error(sprintf('The "%s" class is deprecated since Symfony 4.4, use "%s" instead.', ClassNotFoundException::class, \Symfony\Component\ErrorHandler\Exception\ClassNotFoundException::class), E_USER_DEPRECATED);
14+
@trigger_error(sprintf('The "%s" class is deprecated since Symfony 4.4, use "%s" instead.', ClassNotFoundException::class, \Symfony\Component\ErrorHandler\Error\ClassNotFoundError::class), E_USER_DEPRECATED);
1515

1616
/**
1717
* Class (or Trait or Interface) Not Found Exception.
1818
*
1919
* @author Konstanton Myakshin <koc-dp@yandex.ru>
2020
*
21-
* @deprecated since Symfony 4.4, use Symfony\Component\ErrorHandler\Exception\ClassNotFoundException instead.
21+
* @deprecated since Symfony 4.4, use Symfony\Component\ErrorHandler\Error\ClassNotFoundError instead.
2222
*/
2323
class ClassNotFoundException extends FatalErrorException
2424
{

src/Symfony/Component/Debug/Exception/FatalErrorException.php

+2-2
Original file line numberDiff line numberDiff line change
@@ -11,14 +11,14 @@
1111

1212
namespace Symfony\Component\Debug\Exception;
1313

14-
@trigger_error(sprintf('The "%s" class is deprecated since Symfony 4.4, use "%s" instead.', FatalErrorException::class, \Symfony\Component\ErrorHandler\Exception\FatalErrorException::class), E_USER_DEPRECATED);
14+
@trigger_error(sprintf('The "%s" class is deprecated since Symfony 4.4, use "%s" instead.', FatalErrorException::class, \Symfony\Component\ErrorHandler\Exception\ErrorException::class), E_USER_DEPRECATED);
1515

1616
/**
1717
* Fatal Error Exception.
1818
*
1919
* @author Konstanton Myakshin <koc-dp@yandex.ru>
2020
*
21-
* @deprecated since Symfony 4.4, use Symfony\Component\ErrorHandler\Exception\FatalErrorException instead.
21+
* @deprecated since Symfony 4.4, use Symfony\Component\ErrorHandler\Exception\ErrorException instead.
2222
*/
2323
class FatalErrorException extends \ErrorException
2424
{

src/Symfony/Component/Debug/Exception/FatalThrowableError.php

+2-2
Original file line numberDiff line numberDiff line change
@@ -11,14 +11,14 @@
1111

1212
namespace Symfony\Component\Debug\Exception;
1313

14-
@trigger_error(sprintf('The "%s" class is deprecated since Symfony 4.4, use "%s" instead.', FatalThrowableError::class, \Symfony\Component\ErrorHandler\Exception\FatalThrowableError::class), E_USER_DEPRECATED);
14+
@trigger_error(sprintf('The "%s" class is deprecated since Symfony 4.4, use "%s" instead.', FatalThrowableError::class, \Symfony\Component\ErrorHandler\Exception\ErrorException::class), E_USER_DEPRECATED);
1515

1616
/**
1717
* Fatal Throwable Error.
1818
*
1919
* @author Nicolas Grekas <p@tchwork.com>
2020
*
21-
* @deprecated since Symfony 4.4, use Symfony\Component\ErrorHandler\Exception\FatalThrowableError instead.
21+
* @deprecated since Symfony 4.4, use Symfony\Component\ErrorHandler\Exception\ErrorException instead.
2222
*/
2323
class FatalThrowableError extends FatalErrorException
2424
{

src/Symfony/Component/Debug/Exception/OutOfMemoryException.php

+2-2
Original file line numberDiff line numberDiff line change
@@ -11,14 +11,14 @@
1111

1212
namespace Symfony\Component\Debug\Exception;
1313

14-
@trigger_error(sprintf('The "%s" class is deprecated since Symfony 4.4, use "%s" instead.', OutOfMemoryException::class, \Symfony\Component\ErrorHandler\Exception\OutOfMemoryException::class), E_USER_DEPRECATED);
14+
@trigger_error(sprintf('The "%s" class is deprecated since Symfony 4.4, use "%s" instead.', OutOfMemoryException::class, \Symfony\Component\ErrorHandler\Error\OutOfMemoryError::class), E_USER_DEPRECATED);
1515

1616
/**
1717
* Out of memory exception.
1818
*
1919
* @author Nicolas Grekas <p@tchwork.com>
2020
*
21-
* @deprecated since Symfony 4.4, use Symfony\Component\ErrorHandler\Exception\OutOfMemoryException instead.
21+
* @deprecated since Symfony 4.4, use Symfony\Component\ErrorHandler\Error\OutOfMemoryError instead.
2222
*/
2323
class OutOfMemoryException extends FatalErrorException
2424
{

src/Symfony/Component/Debug/Exception/UndefinedFunctionException.php

+2-2
Original file line numberDiff line numberDiff line change
@@ -11,14 +11,14 @@
1111

1212
namespace Symfony\Component\Debug\Exception;
1313

14-
@trigger_error(sprintf('The "%s" class is deprecated since Symfony 4.4, use "%s" instead.', UndefinedFunctionException::class, \Symfony\Component\ErrorHandler\Exception\UndefinedFunctionException::class), E_USER_DEPRECATED);
14+
@trigger_error(sprintf('The "%s" class is deprecated since Symfony 4.4, use "%s" instead.', UndefinedFunctionException::class, \Symfony\Component\ErrorHandler\Error\UndefinedFunctionError::class), E_USER_DEPRECATED);
1515

1616
/**
1717
* Undefined Function Exception.
1818
*
1919
* @author Konstanton Myakshin <koc-dp@yandex.ru>
2020
*
21-
* @deprecated since Symfony 4.4, use Symfony\Component\ErrorHandler\Exception\UndefinedFunctionException instead.
21+
* @deprecated since Symfony 4.4, use Symfony\Component\ErrorHandler\Error\UndefinedFunctionError instead.
2222
*/
2323
class UndefinedFunctionException extends FatalErrorException
2424
{

src/Symfony/Component/Debug/Exception/UndefinedMethodException.php

+2-2
Original file line numberDiff line numberDiff line change
@@ -11,14 +11,14 @@
1111

1212
namespace Symfony\Component\Debug\Exception;
1313

14-
@trigger_error(sprintf('The "%s" class is deprecated since Symfony 4.4, use "%s" instead.', UndefinedMethodException::class, \Symfony\Component\ErrorHandler\Exception\UndefinedMethodException::class), E_USER_DEPRECATED);
14+
@trigger_error(sprintf('The "%s" class is deprecated since Symfony 4.4, use "%s" instead.', UndefinedMethodException::class, \Symfony\Component\ErrorHandler\Error\UndefinedMethodError::class), E_USER_DEPRECATED);
1515

1616
/**
1717
* Undefined Method Exception.
1818
*
1919
* @author Grégoire Pineau <lyrixx@lyrixx.info>
2020
*
21-
* @deprecated since Symfony 4.4, use Symfony\Component\ErrorHandler\Exception\UndefinedMethodException instead.
21+
* @deprecated since Symfony 4.4, use Symfony\Component\ErrorHandler\Error\UndefinedMethodError instead.
2222
*/
2323
class UndefinedMethodException extends FatalErrorException
2424
{

src/Symfony/Component/Debug/FatalErrorHandler/UndefinedFunctionFatalErrorHandler.php

+2-2
Original file line numberDiff line numberDiff line change
@@ -14,14 +14,14 @@
1414
use Symfony\Component\Debug\Exception\FatalErrorException;
1515
use Symfony\Component\Debug\Exception\UndefinedFunctionException;
1616

17-
@trigger_error(sprintf('The "%s" class is deprecated since Symfony 4.4, use "%s" instead.', UndefinedFunctionFatalErrorHandler::class, \Symfony\Component\ErrorHandler\FatalErrorHandler\UndefinedFunctionFatalErrorHandler::class), E_USER_DEPRECATED);
17+
@trigger_error(sprintf('The "%s" class is deprecated since Symfony 4.4, use "%s" instead.', UndefinedFunctionFatalErrorHandler::class, \Symfony\Component\ErrorHandler\ErrorEnhancer\UndefinedFunctionErrorEnhancer::class), E_USER_DEPRECATED);
1818

1919
/**
2020
* ErrorHandler for undefined functions.
2121
*
2222
* @author Fabien Potencier <fabien@symfony.com>
2323
*
24-
* @deprecated since Symfony 4.4, use Symfony\Component\ErrorHandler\FatalErrorHandler\UndefinedFunctionFatalErrorHandler instead.
24+
* @deprecated since Symfony 4.4, use Symfony\Component\ErrorHandler\ErrorEnhancer\UndefinedFunctionErrorEnhancer instead.
2525
*/
2626
class UndefinedFunctionFatalErrorHandler implements FatalErrorHandlerInterface
2727
{

src/Symfony/Component/Debug/FatalErrorHandler/UndefinedMethodFatalErrorHandler.php

+2-2
Original file line numberDiff line numberDiff line change
@@ -14,14 +14,14 @@
1414
use Symfony\Component\Debug\Exception\FatalErrorException;
1515
use Symfony\Component\Debug\Exception\UndefinedMethodException;
1616

17-
@trigger_error(sprintf('The "%s" class is deprecated since Symfony 4.4, use "%s" instead.', UndefinedMethodFatalErrorHandler::class, \Symfony\Component\ErrorHandler\FatalErrorHandler\UndefinedMethodFatalErrorHandler::class), E_USER_DEPRECATED);
17+
@trigger_error(sprintf('The "%s" class is deprecated since Symfony 4.4, use "%s" instead.', UndefinedMethodFatalErrorHandler::class, \Symfony\Component\ErrorHandler\ErrorEnhancer\UndefinedMethodErrorEnhancer::class), E_USER_DEPRECATED);
1818

1919
/**
2020
* ErrorHandler for undefined methods.
2121
*
2222
* @author Grégoire Pineau <lyrixx@lyrixx.info>
2323
*
24-
* @deprecated since Symfony 4.4, use Symfony\Component\ErrorHandler\FatalErrorHandler\UndefinedMethodFatalErrorHandler instead.
24+
* @deprecated since Symfony 4.4, use Symfony\Component\ErrorHandler\ErrorEnhancer\UndefinedMethodErrorEnhancer instead.
2525
*/
2626
class UndefinedMethodFatalErrorHandler implements FatalErrorHandlerInterface
2727
{
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,33 @@
1+
<?php
2+
3+
/*
4+
* This file is part of the Symfony package.
5+
*
6+
* (c) Fabien Potencier <fabien@symfony.com>
7+
*
8+
* For the full copyright and license information, please view the LICENSE
9+
* file that was distributed with this source code.
10+
*/
11+
12+
namespace Symfony\Component\ErrorHandler\Error;
13+
14+
class ClassNotFoundError extends \Error
15+
{
16+
/**
17+
* {@inheritdoc}
18+
*/
19+
public function __construct(string $message, \Throwable $previous)
20+
{
21+
parent::__construct($message, $previous->getCode(), $previous->getPrevious());
22+
23+
foreach ([
24+
'file' => $previous->getFile(),
25+
'line' => $previous->getLine(),
26+
'trace' => $previous->getTrace(),
27+
] as $property => $value) {
28+
$refl = new \ReflectionProperty(\Error::class, $property);
29+
$refl->setAccessible(true);
30+
$refl->setValue($this, $value);
31+
}
32+
}
33+
}

src/Symfony/Component/ErrorHandler/Exception/FatalErrorException.php renamed to src/Symfony/Component/ErrorHandler/Error/FatalError.php

+27-16
Original file line numberDiff line numberDiff line change
@@ -9,27 +9,29 @@
99
* file that was distributed with this source code.
1010
*/
1111

12-
namespace Symfony\Component\ErrorHandler\Exception;
12+
namespace Symfony\Component\ErrorHandler\Error;
1313

14-
/**
15-
* Fatal Error Exception.
16-
*
17-
* @author Konstanton Myakshin <koc-dp@yandex.ru>
18-
*/
19-
class FatalErrorException extends \ErrorException
14+
class FatalError extends \Error
2015
{
21-
public function __construct(string $message, int $code, int $severity, string $filename, int $lineno, int $traceOffset = null, bool $traceArgs = true, array $trace = null, \Throwable $previous = null)
16+
private $error;
17+
18+
/**
19+
* {@inheritdoc}
20+
*
21+
* @param array $error An array as returned by error_get_last()
22+
*/
23+
public function __construct(string $message, int $code, array $error, int $traceOffset = null, bool $traceArgs = true, array $trace = null)
2224
{
23-
parent::__construct($message, $code, $severity, $filename, $lineno, $previous);
25+
parent::__construct($message, $code);
26+
27+
$this->error = $error;
2428

2529
if (null !== $trace) {
2630
if (!$traceArgs) {
2731
foreach ($trace as &$frame) {
2832
unset($frame['args'], $frame['this'], $frame);
2933
}
3034
}
31-
32-
$this->setTrace($trace);
3335
} elseif (null !== $traceOffset) {
3436
if (\function_exists('xdebug_get_function_stack')) {
3537
$trace = xdebug_get_function_stack();
@@ -63,15 +65,24 @@ public function __construct(string $message, int $code, int $severity, string $f
6365
} else {
6466
$trace = [];
6567
}
68+
}
6669

67-
$this->setTrace($trace);
70+
foreach ([
71+
'file' => $error['file'],
72+
'line' => $error['line'],
73+
'trace' => $trace,
74+
] as $property => $value) {
75+
$refl = new \ReflectionProperty(\Error::class, $property);
76+
$refl->setAccessible(true);
77+
$refl->setValue($this, $value);
6878
}
6979
}
7080

71-
protected function setTrace(array $trace): void
81+
/**
82+
* {@inheritdoc}
83+
*/
84+
public function getError(): array
7285
{
73-
$traceReflector = new \ReflectionProperty('Exception', 'trace');
74-
$traceReflector->setAccessible(true);
75-
$traceReflector->setValue($this, $trace);
86+
return $this->error;
7687
}
7788
}

src/Symfony/Component/ErrorHandler/Exception/OutOfMemoryException.php renamed to src/Symfony/Component/ErrorHandler/Error/OutOfMemoryError.php

+2-7
Original file line numberDiff line numberDiff line change
@@ -9,13 +9,8 @@
99
* file that was distributed with this source code.
1010
*/
1111

12-
namespace Symfony\Component\ErrorHandler\Exception;
12+
namespace Symfony\Component\ErrorHandler\Error;
1313

14-
/**
15-
* Out of memory exception.
16-
*
17-
* @author Nicolas Grekas <p@tchwork.com>
18-
*/
19-
class OutOfMemoryException extends FatalErrorException
14+
class OutOfMemoryError extends FatalError
2015
{
2116
}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,33 @@
1+
<?php
2+
3+
/*
4+
* This file is part of the Symfony package.
5+
*
6+
* (c) Fabien Potencier <fabien@symfony.com>
7+
*
8+
* For the full copyright and license information, please view the LICENSE
9+
* file that was distributed with this source code.
10+
*/
11+
12+
namespace Symfony\Component\ErrorHandler\Error;
13+
14+
class UndefinedFunctionError extends \Error
15+
{
16+
/**
17+
* {@inheritdoc}
18+
*/
19+
public function __construct(string $message, \Throwable $previous)
20+
{
21+
parent::__construct($message, $previous->getCode(), $previous->getPrevious());
22+
23+
foreach ([
24+
'file' => $previous->getFile(),
25+
'line' => $previous->getLine(),
26+
'trace' => $previous->getTrace(),
27+
] as $property => $value) {
28+
$refl = new \ReflectionProperty(\Error::class, $property);
29+
$refl->setAccessible(true);
30+
$refl->setValue($this, $value);
31+
}
32+
}
33+
}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,33 @@
1+
<?php
2+
3+
/*
4+
* This file is part of the Symfony package.
5+
*
6+
* (c) Fabien Potencier <fabien@symfony.com>
7+
*
8+
* For the full copyright and license information, please view the LICENSE
9+
* file that was distributed with this source code.
10+
*/
11+
12+
namespace Symfony\Component\ErrorHandler\Error;
13+
14+
class UndefinedMethodError extends \Error
15+
{
16+
/**
17+
* {@inheritdoc}
18+
*/
19+
public function __construct(string $message, \Throwable $previous)
20+
{
21+
parent::__construct($message, $previous->getCode(), $previous->getPrevious());
22+
23+
foreach ([
24+
'file' => $previous->getFile(),
25+
'line' => $previous->getLine(),
26+
'trace' => $previous->getTrace(),
27+
] as $property => $value) {
28+
$refl = new \ReflectionProperty(\Error::class, $property);
29+
$refl->setAccessible(true);
30+
$refl->setValue($this, $value);
31+
}
32+
}
33+
}

0 commit comments

Comments
 (0)