Skip to content

Commit

Permalink
Merge branch '4.4'
Browse files Browse the repository at this point in the history
* 4.4:
  [Messenger] use events consistently in worker
  Deprecate things that prevent \Throwable from bubbling down
  • Loading branch information
nicolas-grekas committed Nov 5, 2019
2 parents 628980e + 7489726 commit f443bc5
Show file tree
Hide file tree
Showing 2 changed files with 61 additions and 5 deletions.
64 changes: 59 additions & 5 deletions Application.php
Expand Up @@ -121,13 +121,10 @@ public function run(InputInterface $input = null, OutputInterface $output = null
}

$renderException = function (\Throwable $e) use ($output) {
if (!$e instanceof \Exception) {
$e = class_exists(ErrorException::class) ? new ErrorException($e) : new \ErrorException($e->getMessage(), $e->getCode(), E_ERROR, $e->getFile(), $e->getLine());
}
if ($output instanceof ConsoleOutputInterface) {
$this->renderException($e, $output->getErrorOutput());
$this->renderThrowable($e, $output->getErrorOutput());
} else {
$this->renderException($e, $output);
$this->renderThrowable($e, $output);
}
};
if ($phpHandler = set_exception_handler($renderException)) {
Expand Down Expand Up @@ -763,20 +760,77 @@ public static function getAbbreviations(array $names)

/**
* Renders a caught exception.
*
* @deprecated since Symfony 4.4, use "renderThrowable()" instead
*/
public function renderException(\Exception $e, OutputInterface $output)
{
@trigger_error(sprintf('The "%s::renderException()" method is deprecated since Symfony 4.4, use "renderThrowable()" instead.', __CLASS__), E_USER_DEPRECATED);

$output->writeln('', OutputInterface::VERBOSITY_QUIET);

$this->doRenderException($e, $output);

$this->finishRenderThrowableOrException($output);
}

public function renderThrowable(\Throwable $e, OutputInterface $output): void
{
if (__CLASS__ !== \get_class($this) && __CLASS__ === (new \ReflectionMethod($this, 'renderThrowable'))->getDeclaringClass()->getName() && __CLASS__ !== (new \ReflectionMethod($this, 'renderException'))->getDeclaringClass()->getName()) {
@trigger_error(sprintf('The "%s::renderException()" method is deprecated since Symfony 4.4, use "renderThrowable()" instead.', __CLASS__), E_USER_DEPRECATED);

if (!$e instanceof \Exception) {
$e = class_exists(ErrorException::class) ? new ErrorException($e) : new \ErrorException($e->getMessage(), $e->getCode(), E_ERROR, $e->getFile(), $e->getLine());
}

$this->renderException($e, $output);

return;
}

$output->writeln('', OutputInterface::VERBOSITY_QUIET);

$this->doRenderThrowable($e, $output);

$this->finishRenderThrowableOrException($output);
}

private function finishRenderThrowableOrException(OutputInterface $output): void
{
if (null !== $this->runningCommand) {
$output->writeln(sprintf('<info>%s</info>', sprintf($this->runningCommand->getSynopsis(), $this->getName())), OutputInterface::VERBOSITY_QUIET);
$output->writeln('', OutputInterface::VERBOSITY_QUIET);
}
}

/**
* @deprecated since Symfony 4.4, use "doRenderThrowable()" instead
*/
protected function doRenderException(\Exception $e, OutputInterface $output)
{
@trigger_error(sprintf('The "%s::doRenderException()" method is deprecated since Symfony 4.4, use "doRenderThrowable()" instead.', __CLASS__), E_USER_DEPRECATED);

$this->doActuallyRenderThrowable($e, $output);
}

protected function doRenderThrowable(\Throwable $e, OutputInterface $output): void
{
if (__CLASS__ !== \get_class($this) && __CLASS__ === (new \ReflectionMethod($this, 'doRenderThrowable'))->getDeclaringClass()->getName() && __CLASS__ !== (new \ReflectionMethod($this, 'doRenderException'))->getDeclaringClass()->getName()) {
@trigger_error(sprintf('The "%s::doRenderException()" method is deprecated since Symfony 4.4, use "doRenderThrowable()" instead.', __CLASS__), E_USER_DEPRECATED);

if (!$e instanceof \Exception) {
$e = class_exists(ErrorException::class) ? new ErrorException($e) : new \ErrorException($e->getMessage(), $e->getCode(), E_ERROR, $e->getFile(), $e->getLine());
}

$this->doRenderException($e, $output);

return;
}

$this->doActuallyRenderThrowable($e, $output);
}

private function doActuallyRenderThrowable(\Throwable $e, OutputInterface $output): void
{
do {
$message = trim($e->getMessage());
Expand Down
2 changes: 2 additions & 0 deletions CHANGELOG.md
Expand Up @@ -25,6 +25,8 @@ CHANGELOG
* marked all dispatched event classes as `@final`
* added support for displaying table horizontally
* deprecated returning `null` from `Command::execute()`, return `0` instead
* Deprecated the `Application::renderException()` and `Application::doRenderException()` methods,
use `renderThrowable()` and `doRenderThrowable()` instead.

4.3.0
-----
Expand Down

0 comments on commit f443bc5

Please sign in to comment.