Fixed Console fails to render Errors, expects Exceptions (php7.3)

Xon

Well-known member
Affected version
2.1.2
Code:
TypeError: Argument 1 passed to Symfony\Component\Console\Application::renderException() must be an instance of Exception, instance of Error given, called in /var/www/sites/html/src/XF/Cli/Command/AddOnSubAction.php on line 130
src/vendor/symfony/console/Application.php:732
Generated by: Unknown account
May 9, 2019 at 2:15 AM

Stack trace
#0 src/XF/Cli/Command/AddOnSubAction.php(130): Symfony\Component\Console\Application->renderException(Object(Error), Object(Symfony\Component\Console\Output\ConsoleOutput))
#1 src/vendor/symfony/console/Command/Command.php(255): XF\Cli\Command\AddOnSubAction->execute(Object(Symfony\Component\Console\Input\ArgvInput), Object(Symfony\Component\Console\Output\ConsoleOutput))
#2 src/vendor/symfony/console/Application.php(960): Symfony\Component\Console\Command\Command->run(Object(Symfony\Component\Console\Input\ArgvInput), Object(Symfony\Component\Console\Output\ConsoleOutput))
#3 src/vendor/symfony/console/Application.php(255): Symfony\Component\Console\Application->doRunCommand(Object(XF\Cli\Command\AddOnSubAction), Object(Symfony\Component\Console\Input\ArgvInput), Object(Symfony\Component\Console\Output\ConsoleOutput))
#4 src/vendor/symfony/console/Application.php(148): Symfony\Component\Console\Application->doRun(Object(Symfony\Component\Console\Input\ArgvInput), Object(Symfony\Component\Console\Output\ConsoleOutput))
#5 src/XF/Cli/Runner.php(63): Symfony\Component\Console\Application->run(Object(Symfony\Component\Console\Input\ArgvInput), Object(Symfony\Component\Console\Output\ConsoleOutput))
#6 cmd.php(16): XF\Cli\Runner->run()
#7 {main}

Happens when trying to call an invalid static method in an upgrade step. The correct exception/error did log to the xf_error_log
 
Can you provide a code snippet to reproduce? I'm testing with PHP 7.3.7 and not seeing an error so far. I presume the error is coming from the catch with \Throwable $e in it?
 
The XF\Cli\Command\AddOnSubAction::execute trait has this catch block;

Code:
catch (\Throwable $e)
{
   // taking this approach so that we don't get double logging
   \XF::logException($e, true, '', true);

   $output->setVerbosity(OutputInterface::VERBOSITY_VERBOSE);
   $this->getApplication()->renderException($e, $output);

   return 222;
}

But the generic CLI runner has this; XF\Cli\Runner::run()

Code:
catch (\Throwable $e)
{
   \XF::logException($e, true); // exiting so rollback
   $console->renderException(
      new \ErrorException($e->getMessage(), $e->getCode(), E_ERROR, $e->getFile(), $e->getLine(), $e),
      $output)
   ;
   $this->outputAdditionalInfo($e, $output);
   $exitCode = 1;
}

It looks like symfony has some goop around renderException for the exception handler it calls, but the AddOnSubAction stuff directly calls renderException with a Throwable but it takes an Exception
 
Thank you for reporting this issue. It has now been resolved and we are aiming to include it in a future XF release (2.1.5).

Change log:
Wrap Throwable in ErrorException for compatibility with Symfony component
Any changes made as a result of this issue being resolved may not be rolled out here until later.
 
Top Bottom