/**
  * handle errors
  *
  * @param \Exception                                       $error  the error stack
  * @param Symfony\Component\Console\Output\OutputInterface $output the ooutput interface
  * @param string                                           $prefix the prefix to indent the text
  */
 protected function displayError(\Exception $error, OutputInterface $output, $prefix = '')
 {
     $output->writeln('<error>' . $prefix . $error->getMessage() . '</error>');
     if ($error->getPrevious()) {
         $this->displayError($error->getPrevious(), $output, "\t - ");
     }
 }
Example #2
0
 public static function getFilteredStackTrace(Exception $e, $asString = true)
 {
     $stackTrace = $asString ? '' : array();
     $trace = $e->getPrevious() ? $e->getPrevious()->getTrace() : $e->getTrace();
     if ($e instanceof \PHPUnit_Framework_ExceptionWrapper) {
         $trace = $e->getSerializableTrace();
     }
     foreach ($trace as $step) {
         if (self::classIsFiltered($step)) {
             continue;
         }
         if (self::fileIsFiltered($step)) {
             continue;
         }
         if (!$asString) {
             $stackTrace[] = $step;
             continue;
         }
         if (!isset($step['file'])) {
             continue;
         }
         $stackTrace .= $step['file'] . ':' . $step['line'] . "\n";
     }
     return $stackTrace;
 }
Example #3
0
 public static function exceptionToArray(\Exception $e)
 {
     $a = array('code' => $e->getCode(), 'message' => $e->getMessage());
     if ($e->getPrevious() !== null) {
         $a['previous'] = self::exceptionToArray($e->getPrevious());
     }
     return $a;
 }
Example #4
0
 /**
  * Format exception
  *
  * @param Exception $e Exception
  * @return array
  */
 private function _formatException(Exception $e)
 {
     $result = ['message' => $e->getMessage(), 'code' => $e->getCode(), 'trace' => $e->getTrace()];
     if ($previous = $e->getPrevious()) {
         $result['previous'] = $this->_formatException($e->getPrevious());
     }
     return $result;
 }
function displayError(Exception $error)
{
    echo $error->getMessage() . "\n";
    if ($error->getPrevious()) {
        echo ' Underlying error: ';
        displayError($error->getPrevious());
    }
}
Example #6
0
 /**
  * Returns an Inspector for a previous Exception, if any.
  *
  * @return Inspector
  */
 public function getPreviousExceptionInspector()
 {
     if ($this->previousExceptionInspector === null) {
         $previousException = $this->exception->getPrevious();
         if ($previousException) {
             $this->previousExceptionInspector = new Inspector($previousException);
         }
     }
     return $this->previousExceptionInspector;
 }
Example #7
0
 public static function findCodeDb(Exception $e)
 {
     if (isset($e->errorInfo)) {
         return $e->errorInfo;
     }
     if ($e->getPrevious()) {
         return self::findCodeDb($e->getPrevious());
     } else {
         return false;
     }
 }
 /**
  * @param \Exception $exception
  *
  * @return array
  */
 protected function buildError(\Exception $exception)
 {
     $result = ['code' => $exception->getCode(), 'message' => $exception->getMessage(), 'previous' => null, 'data' => null];
     if ($exception->getPrevious() !== null) {
         $result['previous'] = $this->buildError($exception->getPrevious());
     }
     if ($exception instanceof ExceptionInterface) {
         $result['data'] = $exception->getMetaData();
     }
     return $result;
 }
Example #9
0
 /**
  * @param \Exception $exception
  * @return string
  */
 private static function serializeException(\Exception $exception)
 {
     $appendix = '';
     $info = array_merge($exception->getMessage() ? array(self::serialize($exception->getMessage())) : array(), $exception->getCode() ? array(self::serialize($exception->getCode())) : array());
     if ($info) {
         $appendix = '(' . implode(', ', $info) . ')';
     }
     if ($exception->getPrevious()) {
         $appendix .= ' <- ' . self::serializeException($exception->getPrevious());
     }
     return self::serializeObject($exception, $appendix);
 }
 /**
  * Create Serializable exception from real exception
  * @param \Exception $exception
  */
 public function __construct(\Exception $exception)
 {
     $this->message = $exception->getMessage();
     $this->traceString = $exception->getTraceAsString();
     $this->code = $exception->getCode();
     $this->file = $exception->getFile();
     $this->line = $exception->getLine();
     if ($exception->getPrevious() instanceof \Exception) {
         $this->previous = new SerializableException($exception->getPrevious());
     }
     $this->trace = $exception->getTrace();
     $this->cleanupTrace();
 }
 /**
  * {@inheritdoc}
  */
 public function handle(\Exception $exception)
 {
     if (null !== ($preEx = $exception->getPrevious())) {
         throw $preEx;
     }
     throw $exception;
 }
Example #12
0
function displayExceptionObject(Exception $e)
{
    echo "\$e = >{$e}<\n";
    // calls __toString
    echo "getMessage:       >" . $e->getMessage() . "<\n";
    echo "getCode:          >" . $e->getCode() . "<\n";
    echo "getPrevious:      >" . $e->getPrevious() . "<\n";
    echo "getFile:          >" . $e->getFile() . "<\n";
    echo "getLine:          >" . $e->getLine() . "<\n";
    echo "getTraceAsString: >" . $e->getTraceAsString() . "<\n";
    $traceInfo = $e->getTrace();
    var_dump($traceInfo);
    echo "Trace Info:" . (count($traceInfo) == 0 ? " none\n" : "\n");
    foreach ($traceInfo as $traceInfoKey => $traceLevel) {
        echo "Key[{$traceInfoKey}]:\n";
        foreach ($traceLevel as $levelKey => $levelVal) {
            if ($levelKey != "args") {
                echo "  Key[{$levelKey}] => >{$levelVal}<\n";
            } else {
                echo "  Key[{$levelKey}]:\n";
                foreach ($levelVal as $argKey => $argVal) {
                    echo "    Key[{$argKey}] => >{$argVal}<\n";
                }
            }
        }
    }
}
Example #13
0
 /**
  * Handles a thrown exception.  Will also log extra information if the exception happens to by a MySql deadlock.
  *
  * @param \Exception $exception The exception captured.
  *
  * @return null
  */
 protected function handleException($exception)
 {
     // Log MySQL deadlocks
     if ($exception instanceof \CDbException && strpos($exception->getMessage(), 'Deadlock') !== false) {
         $data = craft()->db->createCommand('SHOW ENGINE INNODB STATUS')->query();
         $info = $data->read();
         $info = serialize($info);
         Craft::log('Deadlock error, innodb status: ' . $info, LogLevel::Error, 'system.db.CDbCommand');
     }
     // If this is a Twig Runtime exception, use the previous one instead
     if ($exception instanceof \Twig_Error_Runtime) {
         if ($previousException = $exception->getPrevious()) {
             $exception = $previousException;
         }
     }
     // Special handling for Twig syntax errors
     if ($exception instanceof \Twig_Error) {
         $this->handleTwigError($exception);
     } else {
         if ($exception instanceof DbConnectException) {
             $this->handleDbConnectionError($exception);
         } else {
             parent::handleException($exception);
         }
     }
 }
 /**
  * Outputs the error popup, or a plain message, depending on the response content type.
  *
  * @param \Exception|\Error      $exception Note: can't be type hinted, for PHP7 compat.
  * @param ResponseInterface|null $response  If null, it outputs directly to the client. Otherwise, it assumes the
  *                                          object is a new blank response.
  * @return ResponseInterface|null
  */
 static function display($exception, ResponseInterface $response = null)
 {
     // For HTML pages, output the error popup
     if (strpos(get($_SERVER, 'HTTP_ACCEPT'), 'text/html') !== false) {
         ob_start();
         ErrorConsoleRenderer::renderStyles();
         $stackTrace = self::getStackTrace($exception->getPrevious() ?: $exception);
         ErrorConsoleRenderer::renderPopup($exception, self::$appName, $stackTrace);
         $popup = ob_get_clean();
         // PSR-7 output
         if ($response) {
             $response->getBody()->write($popup);
             return $response->withStatus(500);
         }
         // Direct output
         echo $popup;
     } else {
         // PSR-7 output
         if ($response) {
             $response->getBody()->write($exception->getMessage());
             if (self::$devEnv) {
                 $response->getBody()->write("\n\nStack trace:\n" . $exception->getTraceAsString());
             }
             return $response->withoutHeader('Content-Type')->withHeader('Content-Type', 'text-plain')->withStatus(500);
         }
         // Direct output
         header("Content-Type: text/plain");
         http_response_code(500);
         echo $exception->getMessage();
         if (self::$devEnv) {
             echo "\n\nStack trace:\n" . $exception->getTraceAsString();
         }
     }
     return null;
 }
 public static function handle(\Exception $ex)
 {
     if ($ex->getPrevious() instanceof ConsoleException) {
         Console::error($ex->getMessage());
         return;
     }
     $handles = Settings::load('exception');
     if (isset($handles) && !empty($handles)) {
         foreach ($handles as $key => $value) {
             if (self::recursive($ex, $key)) {
                 if (is_callable($value)) {
                     call_user_func($value, $ex);
                     return;
                 } else {
                     /** @var ExceptionHandle $handle */
                     $handle = DI::get($value);
                     if (isset($handle)) {
                         $handle->handle();
                         return;
                     }
                 }
             }
         }
     }
     throw $ex;
 }
Example #16
0
/**
 * 2016-07-18
 * @param E $e
 * @return E
 */
function df_ef(E $e)
{
    while ($e->getPrevious()) {
        $e = $e->getPrevious();
    }
    return $e;
}
Example #17
0
File: Errors.php Project: wuxw/YYF
 /**
  * Send exception message to client
  * @param \Exception $exception
  */
 public function dispatchException(\Exception $exception)
 {
     if ($this->isActive()) {
         if ($this->dispatchPreviousExceptions && $exception->getPrevious()) {
             $this->dispatchException($exception->getPrevious());
         }
         $message = new \PhpConsole\ErrorMessage();
         $message->code = $exception->getCode();
         $message->class = get_class($exception);
         $message->data = $this->dumper->dump($exception->getMessage());
         $message->file = $exception->getFile();
         $message->line = $exception->getLine();
         $message->trace = self::fetchTrace($exception->getTrace(), $message->file, $message->line);
         $this->sendMessage($message);
     }
 }
Example #18
0
 /**
  * Wraps an Exception object's backtrace.
  *
  * @param Exception $e  The exception to wrap.
  */
 public function createFromException(Exception $e)
 {
     $this->backtrace = $e->getTrace();
     if ($previous = $e->getPrevious()) {
         $backtrace = new self($previous);
         $this->backtrace = array_merge($backtrace->backtrace, $this->backtrace);
     }
 }
Example #19
0
 /**
  * Returns an array that can be handled by devLog with the information from an exception.
  *
  * @param \Exception $exception
  * @return array
  */
 public static function exceptionToArray($exception, $includePrevious = false)
 {
     $array = ['message' => $exception->getMessage(), 'code' => $exception->getCode(), 'file' => $exception->getFile(), 'line' => $exception->getLine(), 'trace' => $exception->getTraceAsString()];
     if ($includePrevious) {
         $array['previous'] = self::exceptionToArray($exception->getPrevious(), true);
     }
     return $array;
 }
 public function handleException(\Exception $ex)
 {
     if (!$ex instanceof ResourceException) {
         return;
     }
     $httpException = $ex->getPrevious();
     $this->logger->error($ex->getMessage(), [(string) $httpException]);
 }
Example #21
0
 protected function getParentExceptionsMessage(\Exception $exp)
 {
     $message = array();
     while ($exp->getPrevious() instanceof \Exception) {
         $exp = $exp->getPrevious();
         $message[] = get_class($exp) . ": " . $exp->getMessage();
     }
     return empty($message) ? '<none>' : $message;
 }
Example #22
0
 /**
  * @param \Exception $exception
  * @throws \Exception
  */
 private function handleKnownExceptionsElseThrowAgain(\Exception $exception)
 {
     $previousException = $exception->getPrevious();
     if ($this->actionMethodName === 'detailAction' && $previousException instanceof \TYPO3\CMS\Extbase\Property\Exception && isset($this->settings['detail']['errorHandling'])) {
         $this->handleNoNewsFoundError($this->settings['detail']['errorHandling']);
     } else {
         throw $exception;
     }
 }
 protected function normalizeException(Exception $e)
 {
     $previousText = '';
     if (is_callable(array($e, 'getPrevious')) && ($previous = $e->getPrevious())) {
         do {
             $previousText .= ', ' . get_class($previous) . ': ' . $previous->getMessage() . ' at ' . $previous->getFile() . ':' . $previous->getLine();
         } while ($previous = $previous->getPrevious());
     }
     return '[object] (' . get_class($e) . ': ' . $e->getMessage() . ' at ' . $e->getFile() . ':' . $e->getLine() . $previousText . ')';
 }
 /**
  * Default error page
  *
  * @param   \Exception $e
  * @return  string
  */
 public function error(\Exception $e)
 {
     $title = 'Error';
     $previous = $e->getPrevious();
     $message = $this->_getExceptionMessage($e, true);
     if ($previous) {
         $message .= $this->_getExceptionMessage($previous, false);
     }
     $this->_render($message, 'Oups :(', HttpStatus::ERROR, array('page_title' => $title));
 }
Example #25
0
 protected function normalizeException(Exception $e)
 {
     $previousText = '';
     if (version_compare(PHP_VERSION, '5.3') >= 0 && ($previous = $e->getPrevious())) {
         do {
             $previousText .= ', ' . get_class($previous) . ': ' . $previous->getMessage() . ' at ' . $previous->getFile() . ':' . $previous->getLine();
         } while ($previous = $previous->getPrevious());
     }
     return '[object] (' . get_class($e) . ': ' . $e->getMessage() . ' at ' . $e->getFile() . ':' . $e->getLine() . $previousText . ')';
 }
 /**
  * Sets up the custom exception and copies over original exception values.
  *
  * @param Exception $exception - the exception to be wrapped
  */
 public function __construct(\Exception $exception)
 {
     $message = $exception->getMessage();
     $code = $exception->getCode();
     if ($exception instanceof HttpException) {
         $message = $exception->getResponse()->getBody()->__toString();
         $this->body = json_decode($message, true);
         $code = $exception->getResponse()->getStatusCode();
     }
     parent::__construct($message, $code, $exception->getPrevious());
 }
Example #27
0
 public function appendError($logId, \Exception $exception)
 {
     if ($exception instanceof DisplayException) {
         return;
     }
     $previousException = $exception->getPrevious();
     if ($previousException instanceof \Exception) {
         $this->appendError($logId, $previousException);
     }
     $this->connection->insert('fusio_log_error', array('logId' => $logId, 'message' => $exception->getMessage(), 'trace' => $exception->getTraceAsString(), 'file' => $exception->getFile(), 'line' => $exception->getLine()));
 }
Example #28
0
 public function handleException(Exception $e)
 {
     $type = $e instanceof ErrorException ? 'PHP Error' : 'PHP Exception';
     $message = "{$type} in " . $e->getFile() . ' on line ' . $e->getLine() . ': ' . $e->getMessage();
     if ($prev_e = $e->getPrevious()) {
         $e = $prev_e;
         $type = $e instanceof ErrorException ? 'PHP Error' : 'PHP Exception';
         $message .= ";  Previous {$type} in " . $e->getFile() . ' on line ' . $e->getLine() . ': ' . $e->getMessage();
     }
     $this->sendFailure($message);
 }
 /**
  * @param \Exception $dispatchException
  * @param array $pendingCommands
  * @return CommandDispatchException
  */
 public static function wrap(\Exception $dispatchException, array $pendingCommands)
 {
     if ($dispatchException instanceof MessageDispatchException) {
         $ex = parent::failed($dispatchException->getFailedDispatchEvent(), $dispatchException->getPrevious());
         $ex->pendingCommands = $pendingCommands;
         return $ex;
     }
     $ex = new static("Command dispatch failed. See previous exception for details.", 422, $dispatchException);
     $ex->pendingCommands = $pendingCommands;
     return $ex;
 }
Example #30
0
 /**
  * @param \Exception $exception
  * @return ClientException|ServerException
  */
 public static function wrapException(\Exception $exception)
 {
     $causingException = $exception->getPrevious();
     if ($causingException instanceof HttpException\ConnectException || $exception instanceof CommandException\CommandServerException) {
         return new ServerException(sprintf('Server error: %s', $exception->getMessage()), $exception);
     }
     // Consider everything else as client side errors:
     // - Server side validation errors resulting in code 400 (CommandException\CommandClientException)
     // - Client side Validation, request is not sent (HttpException\CommandException)
     // - And every else...
     return new ClientException(sprintf('Client error: %s', $exception->getMessage()), $exception);
 }