-
-
Notifications
You must be signed in to change notification settings - Fork 9.6k
Tweak error/exception handler registration #58372
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
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 |
---|---|---|
|
@@ -60,6 +60,7 @@ | |
use Symfony\Component\Mime\DependencyInjection\AddMimeTypeGuesserPass; | ||
use Symfony\Component\PropertyInfo\DependencyInjection\PropertyInfoPass; | ||
use Symfony\Component\Routing\DependencyInjection\RoutingResolverPass; | ||
use Symfony\Component\Runtime\SymfonyRuntime; | ||
use Symfony\Component\Serializer\DependencyInjection\SerializerPass; | ||
use Symfony\Component\Translation\DependencyInjection\TranslationDumperPass; | ||
use Symfony\Component\Translation\DependencyInjection\TranslationExtractorPass; | ||
|
@@ -91,7 +92,16 @@ class FrameworkBundle extends Bundle | |
{ | ||
public function boot() | ||
{ | ||
ErrorHandler::register(null, false)->throwAt($this->container->getParameter('debug.error_handler.throw_at'), true); | ||
if (class_exists(SymfonyRuntime::class)) { | ||
$handler = set_error_handler('var_dump'); | ||
restore_error_handler(); | ||
} else { | ||
$handler = [ErrorHandler::register(null, false)]; | ||
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. When symfony/runtime is not found, the index.php file registers ErrorHandler only in debug mode, so we need to register it to not break prod mode. 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. shouldn't we check whether it is already registered ? Maybe some devs have changed the index.php file. And wouldn't this still cause issues with PHPUnit 11 then when booting a kernel during tests ? 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. The |
||
} | ||
|
||
if (\is_array($handler) && $handler[0] instanceof ErrorHandler) { | ||
$handler[0]->throwAt($this->container->getParameter('debug.error_handler.throw_at'), true); | ||
} | ||
|
||
if ($this->container->getParameter('kernel.http_method_override')) { | ||
Request::enableHttpMethodParameterOverride(); | ||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -71,15 +71,15 @@ public function __construct(array $options = []) | |
if ($debug) { | ||
umask(0000); | ||
$_SERVER[$debugKey] = $_ENV[$debugKey] = '1'; | ||
|
||
if (false !== $errorHandler = ($options['error_handler'] ?? BasicErrorHandler::class)) { | ||
$errorHandler::register($debug); | ||
$options['error_handler'] = false; | ||
} | ||
} else { | ||
$_SERVER[$debugKey] = $_ENV[$debugKey] = '0'; | ||
} | ||
|
||
if (false !== $errorHandler = ($options['error_handler'] ?? BasicErrorHandler::class)) { | ||
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. untightening the error_handler option from the debug one |
||
$errorHandler::register($debug); | ||
$options['error_handler'] = false; | ||
} | ||
|
||
$this->options = $options; | ||
} | ||
|
||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -24,12 +24,31 @@ class SymfonyErrorHandler | |
{ | ||
public static function register(bool $debug): void | ||
{ | ||
BasicErrorHandler::register($debug); | ||
if (!class_exists(ErrorHandler::class)) { | ||
BasicErrorHandler::register($debug); | ||
|
||
if (class_exists(ErrorHandler::class)) { | ||
return; | ||
} | ||
|
||
error_reporting(-1); | ||
|
||
if (!\in_array(\PHP_SAPI, ['cli', 'phpdbg', 'embed'], true)) { | ||
ini_set('display_errors', $debug); | ||
} elseif (!filter_var(\ini_get('log_errors'), \FILTER_VALIDATE_BOOL) || \ini_get('error_log')) { | ||
// CLI - display errors only if they're not already logged to STDERR | ||
ini_set('display_errors', 1); | ||
} | ||
|
||
if (0 <= \ini_get('zend.assertions')) { | ||
ini_set('zend.assertions', (int) $debug); | ||
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. @nicolas-grekas why are you disabling assertions in non-debug mode ? We are relying on assertions in production mode and this change breaks our application. |
||
} | ||
ini_set('assert.active', 1); | ||
ini_set('assert.exception', 1); | ||
|
||
if ($debug) { | ||
DebugClassLoader::enable(); | ||
restore_error_handler(); | ||
ErrorHandler::register(new ErrorHandler(new BufferingLogger(), $debug)); | ||
} | ||
|
||
ErrorHandler::register(new ErrorHandler(new BufferingLogger(), $debug)); | ||
} | ||
} |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
When symfony/runtime is installed, we assume it will register the ErrorHandler when appropriate.
That's not the case right now, but this PR fixes it.