/** * Method for handling the actual exceptions * * @param \Symfony\Component\Console\Event\ConsoleExceptionEvent $event [description] */ public function onConsoleException(ConsoleExceptionEvent $event) { $command = $event->getCommand(); $exception = $event->getException(); $this->client->notifyOnException($exception); error_log(sprintf("command:%s has thrown %s in: %s:%d", $command->getName(), $exception->getMessage(), $exception->getFile(), $exception->getLine())); }
public function onConsoleException(ConsoleExceptionEvent $event) { $exception = $event->getException(); //This listener only wants to deal with this particular Exception if (!$exception instanceof \GoCardless\Enterprise\Exceptions\ApiException) { return; } $output = $event->getOutput(); $rawReasonPhrase = $exception->getReasonPhrase(); $data = json_decode($rawReasonPhrase, true); $exceptionName = get_class($exception); $gocardlessErrorMessage = isset($data['error']['message']) ? $data['error']['message'] : 'No Gocardless error available'; $fieldErrors = isset($data['error']['errors']) ? $data['error']['errors'] : array(); $output->writeln(""); $output->writeln("Exception: {$exceptionName}"); $output->writeln("---------"); $output->writeln("Gocardless error message: {$gocardlessErrorMessage}"); if ($fieldErrors) { $output->writeln(""); $output->writeln("Field Specific error messages"); } foreach ($fieldErrors as $error) { $output->writeln(""); foreach ($error as $k => $e) { $output->writeln("{$k}: {$e}"); } $output->writeln("-----------"); } $output->writeln("LOOK ABOVE FOR MORE INFORMATION ABOUT THIS EXCEPTION"); }
/** * 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]); }
public function onConsoleException(ConsoleExceptionEvent $event) { $command = $event->getCommand(); $exception = $event->getException(); $message = sprintf('%s: %s (uncaught exception) at %s line %s while running console command `%s`', get_class($exception), $exception->getMessage(), $exception->getFile(), $exception->getLine(), $command->getName()); $this->logger->error($message, array('exception' => $exception)); }
function it_reports_exception_on_console_exception(Notifier $notifier, \Exception $exception, ConsoleExceptionEvent $event) { $this->setException($exception); $event->getException()->willReturn($exception); $notifier->reportException($exception)->shouldBeCalled(); $this->onConsoleException($event); }
/** * Logs exception events for AcmePhp commands. * * @param ConsoleExceptionEvent $event */ public function onConsoleException(ConsoleExceptionEvent $event) { if (!$this->isAcmePhpCommand($event->getCommand())) { return; } $this->logger->error('Exception thrown while running command "{command}". Message: "{message}".', ['command' => $event->getCommand()->getName(), 'message' => $event->getException()->getMessage(), 'exception' => $event->getException()]); }
public function onConsoleException(ConsoleExceptionEvent $event) { $command = $event->getCommand(); if (in_array($command->getName(), ['dz:notification:on_day_end'], TRUE)) { $exception = $event->getException(); $message = sprintf('`%s` [uncaught exception]: command `%s` throws `%s` at `%s` line `%s`', get_class($exception), $command->getName(), $exception->getMessage(), $exception->getFile(), $exception->getLine()); $this->logger->error($message, ['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); }
/** * @param ConsoleExceptionEvent $event */ public function onConsoleException(ConsoleExceptionEvent $event) { $command = $event->getCommand(); $exception = $event->getException(); // Log error with trace $trace = MAUTIC_ENV == 'dev' ? "\n[stack trace]\n" . $exception->getTraceAsString() : ''; $message = sprintf('%s: %s (uncaught exception) at %s line %s while running console command `%s`%s', get_class($exception), $exception->getMessage(), $exception->getFile(), $exception->getLine(), $command->getName(), $trace); // Use notice so it makes it to the log all "perttified" (using error spits it out to console and not the log) $this->logger->notice($message); }
/** * @param GetResponseForExceptionEvent|ConsoleExceptionEvent $event */ public function onKernelException($event) { $exception = $event->getException(); foreach ($this->ignoredExceptions as $ignoredException) { if ($exception instanceof $ignoredException) { return; } } $this->notifier->notify($exception); }
/** * @param ConsoleExceptionEvent $event */ public function onConsoleError(ConsoleExceptionEvent $event) { $exception = $event->getException(); $command = $event->getCommand(); $output = $event->getOutput(); $this->logger->error(sprintf("error while executing %s -> %s", $command->getName(), $exception->getMessage())); if ($this->config->get("common/debug")) { return; } $output->writeln(sprintf("error while executing %s -> %s", $command->getName(), $exception->getMessage())); }
/** * This listener is run when the ConsoleEvents::EXCEPTION event is triggered. * It translate the exception message. If din debug mode the original exception is embedded. * * @param ConsoleExceptionEvent $event */ public function on_exception(ConsoleExceptionEvent $event) { $original_exception = $event->getException(); if ($original_exception instanceof exception_interface) { $parameters = array_merge(array($original_exception->getMessage()), $original_exception->get_parameters()); $message = call_user_func_array(array($this->language, 'lang'), $parameters); if ($this->debug) { $exception = new \RuntimeException($message, $original_exception->getCode(), $original_exception); } else { $exception = new \RuntimeException($message, $original_exception->getCode()); } $event->setException($exception); } }
/** * React to any console exceptions. * * @param ConsoleExceptionEvent $event */ public function onException(ConsoleExceptionEvent $event) { $exception = $event->getException(); // Replace Guzzle connect exceptions with a friendlier message. This // also prevents the user from seeing two exceptions (one direct from // Guzzle, one from RingPHP). if ($exception instanceof ConnectException && strpos($exception->getMessage(), 'cURL error 6') !== false) { $request = $exception->getRequest(); $event->setException(new ConnectionFailedException("Failed to connect to host: " . $request->getHost() . " \nRequest URL: " . $request->getUrl() . " \nPlease check your Internet connection")); $event->stopPropagation(); } // Handle Guzzle client exceptions, i.e. HTTP 4xx errors. if ($exception instanceof ClientException && ($response = $exception->getResponse())) { $request = $exception->getRequest(); try { $response->getBody()->seek(0); $json = $response->json(); } catch (ParseException $e) { $json = []; } // Create a friendlier message for the OAuth2 "Invalid refresh token" // error. if ($response->getStatusCode() === 400 && isset($json['error_description']) && $json['error_description'] === 'Invalid refresh token') { $event->setException(new LoginRequiredException("Invalid refresh token: please log in again." . " \nRequest URL: " . $request->getUrl())); $event->stopPropagation(); } elseif ($response->getStatusCode() === 401) { $event->setException(new LoginRequiredException("Unauthorized: please log in again." . " \nRequest URL: " . $request->getUrl())); $event->stopPropagation(); } } }
public function onConsoleException(ConsoleExceptionEvent $event) { $exception = $event->getException(); $exceptionId = $this->appName . '-' . md5(microtime()); $logData = array('exception' => $exception, 'exceptionId' => $exceptionId); // exception is by default Application Exception $isUserException = false; // SyrupExceptionInterface holds additional data if ($exception instanceof SyrupExceptionInterface) { $logData['data'] = $exception->getData(); $isUserException = $exception->getStatusCode() < 500; } // Log exception $method = $isUserException ? 'error' : 'critical'; $this->logger->{$method}($exception->getMessage(), $logData); }
public function onConsoleException(ConsoleExceptionEvent $event) { $command = $event->getCommand(); $exception = $event->getException(); $message = sprintf('%s: %s (uncaught exception) at %s line %s while running console command `%s`', get_class($exception), $exception->getMessage(), $exception->getFile(), $exception->getLine(), $command->getName()); $this->logger->error($message, array('exception' => $exception)); $this->logger->error('Exception trace:'); // exception related properties $trace = $exception->getTrace(); array_unshift($trace, array('function' => '', 'file' => $exception->getFile() !== null ? $exception->getFile() : 'n/a', 'line' => $exception->getLine() !== null ? $exception->getLine() : 'n/a', 'args' => array())); for ($i = 0, $count = count($trace); $i < $count; ++$i) { $class = isset($trace[$i]['class']) ? $trace[$i]['class'] : ''; $type = isset($trace[$i]['type']) ? $trace[$i]['type'] : ''; $function = $trace[$i]['function']; $file = isset($trace[$i]['file']) ? $trace[$i]['file'] : 'n/a'; $line = isset($trace[$i]['line']) ? $trace[$i]['line'] : 'n/a'; $this->logger->error(sprintf(' %s%s%s() at %s:%s', $class, $type, $function, $file, $line)); } $this->logger->error(''); $this->logger->error(''); }
/** * In case of an exception in scheduler console command * the message should be saved into the scheduler entity * * @param ConsoleExceptionEvent $event */ public function onConsoleException(ConsoleExceptionEvent $event) { /** @var SchedulerCommand $command */ $command = $event->getCommand(); if ($command->getName() != 'campaignchain:scheduler') { return; } // if scheduler is null exception happened in early stage // maybe email should be sent if (!$command->getScheduler()) { return; } /** @var Scheduler $scheduler */ $scheduler = $command->getScheduler(); $scheduler->setMessage($event->getException()->getMessage()); $scheduler->setStatus(Scheduler::STATUS_ERROR); $scheduler->setExecutionEnd(new \DateTime()); $this->em->persist($scheduler); $this->em->flush(); $command->getIo()->error($scheduler->getMessage()); $this->logger->critical($scheduler->getMessage()); }
/** * @param \Symfony\Component\Console\Event\ConsoleExceptionEvent $event * * @return void */ public function onConsoleException(ConsoleExceptionEvent $event) { $exception = $event->getException(); $this->getLogger()->error(sprintf('CLI command "%s" exception, message "%s"', $event->getCommand()->getName(), $exception->getMessage()), ['exception' => $exception]); }
/** * @param \Symfony\Component\Console\Event\ConsoleExceptionEvent $event */ public function onConsoleException(ConsoleExceptionEvent $event) { $this->campfire->notifyOnConsoleException($event->getInput(), $event->getOutput(), $event->getException(), $event->getExitCode()); }
/** * @param ConsoleExceptionEvent $event */ public function onConsoleException(ConsoleExceptionEvent $event) { $this->notifier->reportException($event->getException()); }
/** * {@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(); }
public function onConsoleException(ConsoleExceptionEvent $event) { $ex = $event->getException(); $this->handleException($ex); }
/** * React to any console exceptions. * * @param ConsoleExceptionEvent $event */ public function onException(ConsoleExceptionEvent $event) { $exception = $event->getException(); // Replace Guzzle connect exceptions with a friendlier message. This // also prevents the user from seeing two exceptions (one direct from // Guzzle, one from RingPHP). if ($exception instanceof ConnectException && strpos($exception->getMessage(), 'cURL error 6') !== false) { $request = $exception->getRequest(); $event->setException(new ConnectionFailedException("Failed to connect to host: " . $request->getHost() . " \nPlease check your Internet connection.", $request)); $event->stopPropagation(); } // Handle Guzzle client exceptions, i.e. HTTP 4xx errors. if ($exception instanceof ClientException && ($response = $exception->getResponse())) { $request = $exception->getRequest(); try { $response->getBody()->seek(0); $json = $response->json(); } catch (ParseException $e) { $json = []; } // Create a friendlier message for the OAuth2 "Invalid refresh token" // error. if ($response->getStatusCode() === 400 && isset($json['error_description']) && $json['error_description'] === 'Invalid refresh token') { $event->setException(new LoginRequiredException("Invalid refresh token: please log in again.", $request)); $event->stopPropagation(); } elseif ($response->getStatusCode() === 401) { $event->setException(new LoginRequiredException("Unauthorized: please log in again.", $request)); $event->stopPropagation(); } elseif ($response->getStatusCode() === 403) { $event->setException(new PermissionDeniedException("Permission denied. Check your project or environment permissions.", $request)); $event->stopPropagation(); } } // When an environment is found to be in the wrong state, perhaps our // cache is old - we should invalidate it. if ($exception instanceof EnvironmentStateException) { $command = $event->getCommand(); if ($command instanceof PlatformCommand) { $command->clearEnvironmentsCache(); } } }
/** * Fires when an exception throws on command execution scope ($command->run()) * * @param ConsoleExceptionEvent $event ConsoleExceptionEvent instance * * @return void */ public function onConsoleCommandException(ConsoleExceptionEvent $event) { $command = $event->getCommand(); $container = $command->getApplication()->getContainer(); $container['monolog']->addError(sprintf('Command \'%s\' ErrorMsg: \'%s\'', $command->getName(), $event->getException()->getMessage())); }
/** * Handle the event * * @param ConsoleExceptionEvent $event event */ public function onConsoleException(ConsoleExceptionEvent $event) { $exception = $event->getException(); $sendMail = !in_array(get_class($exception), $this->ignoredClasses); if ($sendMail === true) { $this->createMailAndSend($exception, null, null, $this->command, $this->commandInput); } }
public function onConsoleException(ConsoleExceptionEvent $event) { $exception = $event->getException(); Debugger::log($exception, Debugger::ERROR); }
/** * Report console exception. * * @param \Symfony\Component\Console\Event\ConsoleExceptionEvent $event */ public function onConsoleException(ConsoleExceptionEvent $event) { return $this->reportException($event->getException()); }
public function onConsoleException(ConsoleExceptionEvent $event) { $this->errorHandler->notifyCommandException($event->getException()); }
public function onConsoleException(ConsoleExceptionEvent $event) { $exception = $event->getException(); $this->client->notifyOnException($exception); error_log($exception->getMessage() . ' in: ' . $exception->getFile() . ':' . $exception->getLine()); }
/** * 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(); }
/** * @param ConsoleExceptionEvent $event */ public function onConsoleException(ConsoleExceptionEvent $event) { $exception = $event->getException(); $this->interactor->noticeException($exception); }