/** * Logs console exception * * @param ConsoleExceptionEvent $event The event * * @return void */ public function onConsoleException(ConsoleExceptionEvent $event) { $exception = $event->getException(); $exitCode = $event->getExitCode(); $message = sprintf('%s: "%s" at %s line %s', get_class($exception), $exception->getMessage(), $exception->getFile(), $exception->getLine()); $this->logger->error($message, ['exit_code' => $exitCode, 'exception' => $exception]); }
/** * @param ConsoleExceptionEvent $event */ public function onConsoleException(ConsoleExceptionEvent $event) { $exception = $event->getException(); $metadata = new Metadata(); $metadata->addMetadatum('commandName', $event->getInput()->getFirstArgument()); $metadata->addMetadatum('command', (string) $event->getInput()); $metadata->addMetadatum('exitCode', $event->getExitCode()); $this->errorHandler->handleException($exception, $metadata); }
/** * Runs the current command. * * If an event dispatcher has been attached to the application, * events are also dispatched during the life-cycle of the command. * * @param Command $command A Command instance * @param InputInterface $input An Input instance * @param OutputInterface $output An Output instance * * @return int 0 if everything went fine, or an error code */ protected function doRunCommand(Command $command, InputInterface $input, OutputInterface $output) { foreach ($command->getHelperSet() as $helper) { if ($helper instanceof InputAwareInterface) { $helper->setInput($input); } } if (null === $this->dispatcher) { return $command->run($input, $output); } $event = new ConsoleCommandEvent($command, $input, $output); $this->dispatcher->dispatch(ConsoleEvents::COMMAND, $event); try { $exitCode = $command->run($input, $output); } catch (\Exception $e) { $event = new ConsoleTerminateEvent($command, $input, $output, $e->getCode()); $this->dispatcher->dispatch(ConsoleEvents::TERMINATE, $event); $event = new ConsoleExceptionEvent($command, $input, $output, $e, $event->getExitCode()); $this->dispatcher->dispatch(ConsoleEvents::EXCEPTION, $event); throw $event->getException(); } $event = new ConsoleTerminateEvent($command, $input, $output, $exitCode); $this->dispatcher->dispatch(ConsoleEvents::TERMINATE, $event); return $event->getExitCode(); }
/** * {@inheritdoc} */ protected function doRunCommand(Command $command, InputInterface $input, OutputInterface $output) { $helperSet = $command->getHelperSet(); foreach ($helperSet as $helper) { if ($helper instanceof OutputAwareInterface) { $helper->setOutput($output); } if ($helper instanceof InputAwareInterface) { $helper->setInput($input); } } $event = new ConsoleCommandEvent($command, $input, $output); $this->dispatcher->dispatch(ConsoleEvents::COMMAND, $event); try { $exitCode = $command->run($input, $output); } catch (\Exception $e) { $event = new ConsoleTerminateEvent($command, $input, $output, $e->getCode()); $this->dispatcher->dispatch(ConsoleEvents::TERMINATE, $event); $event = new ConsoleExceptionEvent($command, $input, $output, $e, $event->getExitCode()); $this->dispatcher->dispatch(ConsoleEvents::EXCEPTION, $event); if ($e instanceof UserException) { $this->getHelperSet()->get('gush_style')->error($e->getMessages()); if (OutputInterface::VERBOSITY_VERBOSE <= $output->getVerbosity()) { throw $e; } return $event->getExitCode(); } else { throw $event->getException(); } } $event = new ConsoleTerminateEvent($command, $input, $output, $exitCode); $this->dispatcher->dispatch(ConsoleEvents::TERMINATE, $event); return $event->getExitCode(); }
/** * @param \Symfony\Component\Console\Event\ConsoleExceptionEvent $event */ public function onConsoleException(ConsoleExceptionEvent $event) { $this->campfire->notifyOnConsoleException($event->getInput(), $event->getOutput(), $event->getException(), $event->getExitCode()); }