renderException() public method

Renders a caught exception.
public renderException ( Exception $e, Symfony\Component\Console\Output\OutputInterface $output )
$e Exception An exception instance
$output Symfony\Component\Console\Output\OutputInterface An OutputInterface instance
Example #1
0
 /**
  * Renders a caught exception.
  *
  * @param \Exception      $e      An exception instance
  * @param OutputInterface $output An OutputInterface instance
  */
 public function renderException($e, $output = null)
 {
     if (!$output) {
         $output = $this->output;
         if ($output instanceof ConsoleOutputInterface) {
             $output = $output->getErrorOutput();
         }
     }
     return parent::renderException($e, $output);
 }
 /**
  * Search for dependencies in multiple packages.
  *
  * @param string[]           $packageNames The package names.
  * @param ComposerRepository $repository   The repository.
  *
  * @return void
  */
 private function searchInPackageNames($packageNames, ComposerRepository $repository)
 {
     foreach ($packageNames as $packageName) {
         try {
             $packages = $repository->findPackages($packageName);
             $this->searchInPackages($packages);
         } catch (\Exception $e) {
             $this->application->renderException($e, $this->output);
         }
     }
 }
Example #3
0
 /**
  * Passes exception to error handler before rendering to output
  *
  * @param Exception $e
  * @param OutputInterface $output
  * @return void
  */
 public function renderException(Exception $e, OutputInterface $output)
 {
     if ($this->container->has('error_handler')) {
         /** @var \Whoops\RunInterface $run */
         $run = $this->container->get('error_handler');
         // from now on ConsoleApplication will render exception
         $run->allowQuit(false);
         $run->writeToOutput(false);
         // Ignore the return string, parent call will render exception
         $run->handleException($e);
     }
     parent::renderException($e, $output);
 }
Example #4
0
 /**
  * {@inheritdoc}
  */
 public function renderException(\Exception $e, OutputInterface $output)
 {
     $memory = fopen('php://memory', 'rw');
     $errorStream = new StreamOutput($memory, OutputInterface::VERBOSITY_VERY_VERBOSE, $output ? $output->isDecorated() : null, $output ? $output->getFormatter() : null);
     parent::renderException($e, $errorStream);
     rewind($memory);
     $exception = '';
     while (!feof($memory)) {
         $exception .= fread($memory, 8192);
     }
     fclose($memory);
     $console = new ConsoleOutput();
     $explode = explode("\n", rtrim($exception));
     foreach ($explode as &$line) {
         $line = $console->prefixWithTimestamp($line);
     }
     $output->write(implode("\n", $explode) . "\n");
 }
Example #5
0
 /**
  * Execute console command using it's name.
  *
  * @param string               $command
  * @param array|InputInterface $parameters
  * @param OutputInterface      $output
  * @return CommandOutput
  * @throws ConsoleException
  */
 public function command($command, $parameters = [], OutputInterface $output = null)
 {
     $input = is_object($parameters) ? $parameters : new ArrayInput(compact('command') + $parameters);
     $output = !empty($output) ? $output : new BufferedOutput();
     $outerOutput = $this->container->replace(OutputInterface::class, $output);
     $outerInput = $this->container->replace(InputInterface::class, $input);
     //Go
     $code = self::CODE_UNDEFINED;
     try {
         $code = $this->application()->find($command)->run($input, $output);
     } catch (\Exception $exception) {
         $this->application->renderException($exception, $output);
     } finally {
         $this->container->restore($outerInput);
         $this->container->restore($outerOutput);
     }
     return new CommandOutput($code, $output);
 }
Example #6
0
 /**
  * Set the handlers.
  *
  * @param bool $debug
  */
 public static function register($debug = true)
 {
     $errorLevels = error_reporting();
     if ($debug) {
         $errorLevels |= E_RECOVERABLE_ERROR | E_USER_ERROR | E_DEPRECATED | E_USER_DEPRECATED;
         Debug\DebugClassLoader::enable();
     }
     if (PHP_SAPI !== 'cli') {
         Debug\ErrorHandler::register()->throwAt($errorLevels, true);
         Debug\ExceptionHandler::register($debug);
     } else {
         $consoleHandler = function (\Exception $e) {
             $app = new Application('Bolt CLI', Version::VERSION);
             $output = new ConsoleOutput(OutputInterface::VERBOSITY_DEBUG);
             $app->renderException($e, $output);
             ob_clean();
         };
         Debug\ExceptionHandler::register($debug)->setHandler($consoleHandler);
     }
 }
Example #7
0
 /**
  * Execute console command using it's name.
  *
  * @param string               $command
  * @param array|InputInterface $input
  * @param OutputInterface      $output
  * @return CommandOutput
  * @throws ConsoleException
  */
 public function command($command, $input = [], OutputInterface $output = null)
 {
     if (is_array($input)) {
         $input = new ArrayInput(compact('command') + $input);
     }
     if (empty($output)) {
         $output = new BufferedOutput();
     }
     //todo: do we need input scope?
     $this->openScope($input, $output);
     $code = self::CODE_UNDEFINED;
     try {
         /**
          * Debug: this method creates scope for [[InputInterface]] and [[OutputInterface]].
          */
         $code = $this->application()->find($command)->run($input, $output);
     } catch (\Exception $exception) {
         $this->application->renderException($exception, $output);
     } finally {
         $this->restoreScope();
     }
     return new CommandOutput($code, $output);
 }
Example #8
0
 /**
  * {@inheritDoc}
  */
 public function renderException($exception, $output)
 {
     $io = $this->getIO();
     try {
         $composer = $this->getComposer(false, true);
         if ($composer) {
             $config = $composer->getConfig();
             $minSpaceFree = 1024 * 1024;
             if (($df = @disk_free_space($dir = $config->get('home'))) !== false && $df < $minSpaceFree || ($df = @disk_free_space($dir = $config->get('vendor-dir'))) !== false && $df < $minSpaceFree || ($df = @disk_free_space($dir = sys_get_temp_dir())) !== false && $df < $minSpaceFree) {
                 $io->writeError('<error>The disk hosting ' . $dir . ' is full, this may be the cause of the following exception</error>');
             }
         }
     } catch (\Exception $e) {
     }
     if (defined('PHP_WINDOWS_VERSION_BUILD') && false !== strpos($exception->getMessage(), 'The system cannot find the path specified')) {
         $io->writeError('<error>The following exception may be caused by a stale entry in your cmd.exe AutoRun</error>');
         $io->writeError('<error>Check https://getcomposer.org/doc/articles/troubleshooting.md#-the-system-cannot-find-the-path-specified-windows- for details</error>');
     }
     if (false !== strpos($exception->getMessage(), 'fork failed - Cannot allocate memory')) {
         $io->writeError('<error>The following exception is caused by a lack of memory and not having swap configured</error>');
         $io->writeError('<error>Check https://getcomposer.org/doc/articles/troubleshooting.md#proc-open-fork-failed-errors for details</error>');
     }
     if ($output instanceof ConsoleOutputInterface) {
         parent::renderException($exception, $output->getErrorOutput());
     } else {
         parent::renderException($exception, $output);
     }
 }
Example #9
0
 /**
  * {@inheritDoc}
  */
 public function renderException($exception, $output)
 {
     if ($output instanceof ConsoleOutputInterface) {
         parent::renderException($exception, $output->getErrorOutput());
     } else {
         parent::renderException($exception, $output);
     }
 }
Example #10
0
 /**
  * Render the given exception.
  *
  * @param  \Exception  $e
  * @param  \Symfony\Component\Console\Output\OutputInterface  $output
  * @return void
  */
 public function renderException($e, $output)
 {
     // If we have an exception handler instance, we will call that first in case
     // it has some handlers that need to be run first. We will pass "true" as
     // the second parameter to indicate that it's handling a console error.
     if (isset($this->exceptionHandler)) {
         $this->exceptionHandler->handleConsole($e);
     }
     parent::renderException($e, $output);
 }
Example #11
0
<?php

date_default_timezone_set('Europe/Paris');
require __DIR__ . DIRECTORY_SEPARATOR . '..' . DIRECTORY_SEPARATOR . "vendor" . DIRECTORY_SEPARATOR . "autoload.php";
use Symfony\Component\Console\Helper\HelperSet;
use Symfony\Component\Console\Input\ArgvInput;
use Symfony\Component\Console\Output\ConsoleOutput;
use Symfony\Component\Console\Application;
use Symfony\Component\Console\Input\InputOption;
use Symfony\Component\Console\Input\InputDefinition;
use Evaneos\Flickr\Api\Command\ImportDirectoryCommand;
$console = new Application('Evaneos CLI', 'v0.1');
$console->setCatchExceptions(false);
$input = new ArgvInput();
$output = new ConsoleOutput();
try {
    $commands = array(new ImportDirectoryCommand('flickr:import'));
    foreach ($commands as $command) {
        $console->add($command);
    }
    $result = $console->run($input, $output);
} catch (Exception $e) {
    $console->renderException($e, $output);
    $output->writeln('<error>' . $e->getTraceAsString() . '</error>');
    exit($e->getCode());
}
return $result;
Example #12
0
 /**
  * {@inheritDoc}
  */
 public function renderException($exception, $output)
 {
     try {
         $composer = $this->getComposer(false);
         if ($composer) {
             $config = $composer->getConfig();
             $minSpaceFree = 1024 * 1024;
             if (($df = @disk_free_space($dir = $config->get('home'))) !== false && $df < $minSpaceFree || ($df = @disk_free_space($dir = $config->get('vendor-dir'))) !== false && $df < $minSpaceFree) {
                 $output->writeln('<error>The disk hosting ' . $dir . ' is full, this may be the cause of the following exception</error>');
             }
         }
     } catch (\Exception $e) {
     }
     return parent::renderException($exception, $output);
 }
Example #13
0
 public function renderException($e, $output)
 {
     parent::renderException($e, $output);
     //$this->container->get('ui.shell')->installReadlineCallback();
     $this->container->setParameter('application.exit_code', ResultEvent::ERROR);
 }
Example #14
0
 /**
  * {@inheritdoc}
  */
 public function renderException($e, $output)
 {
     $this->runningCommand = null;
     parent::renderException($e, $output);
 }
Example #15
0
 /**
  * Renders a caught exception.
  * @param $e
  */
 public function renderException($e)
 {
     $this->console->renderException($e, new ConsoleOutput());
     die;
 }
Example #16
0
 /**
  * {@inheritDoc}
  */
 public function renderException(\Exception $exception, OutputInterface $output)
 {
     // Preserve plain echoing to console...
     parent::renderException($exception, $output);
     // ... but pass to logger as well.
     if ($container = $this->kernel->getContainer()) {
         /** @var LoggerInterface $logger */
         $logger = $container->get('logger');
         // We want stack traces, therefore be very verbose.
         $buffer = new BufferedOutput(BufferedOutput::VERBOSITY_VERBOSE);
         parent::renderException($exception, $buffer);
         $logger->error('--------------------------------------------------------');
         foreach (explode("\n", str_replace("\n\n", "\n", $buffer->fetch())) as $line) {
             if ('' !== $line) {
                 $logger->error($line);
             }
         }
         $logger->error('--------------------------------------------------------');
     }
 }