Example #1
0
 /**
  * @inheritDoc
  */
 public function get()
 {
     if (!isset($this->throwable)) {
         throw new LogicException('Throwable must be set to get view.');
     }
     ob_start();
     var_dump($this->throwable->getTrace());
     $fullTrace = ob_get_clean();
     // If xdebug is installed then var_dump is pretty printed for html already.
     if (function_exists('xdebug_var_dump')) {
         $viewTrace = new Text();
         $viewTrace->setHTML5($fullTrace);
         $fullTrace = ['div', ['class' => 'full_trace'], $viewTrace->get()];
     } else {
         $fullTrace = ['pre', ['class' => 'full_trace'], $fullTrace];
     }
     return ['div', ['class' => 'Throwable'], [['div', ['class' => 'location'], 'Thrown at ' . $this->throwable->getFile() . ' line ' . $this->throwable->getLine()], ['pre', [], $this->throwable->getMessage()], ['h2', [], 'Basic Trace'], ['pre', ['class' => 'basic_trace'], $this->throwable->getTraceAsString()], ['h2', [], 'Full Trace'], $fullTrace]];
 }
 /**
  * @param \Exception|\Throwable $exception
  */
 public function handle_exception($exception)
 {
     if (getenv('APP_ENV') === 'dev') {
         list($code, $file, $line, $message, $previous, $trace, $trace_string) = [$exception->getCode(), $exception->getFile(), $exception->getLine(), $exception->getMessage(), $exception->getPrevious(), $exception->getTrace(), $exception->getTraceAsString()];
         $trace_info = "<b>file</b>: {$trace[0]['file']} <b>in line</b> ({$trace[0]['line']})";
         echo "<h2>COGS Runtime Exception: [::{$code}] {$message}</h2>";
         echo "<b>Trace:</b><br>";
         echo "<pre>{$trace_string}</pre>";
         echo "<b>Debug:</b><br>";
         dump(compact('code', 'file', 'line', 'message', 'previous', 'trace'));
     }
 }
Example #3
0
 /**
  * Return an error into an HTTP or JSON data array.
  *
  * @param string $title
  * @return array
  */
 public function error($title = null)
 {
     if ($title == null) {
         $title = $this->debug ? 'The application could not run because of the following error:' : 'A website error has occurred. Sorry for the temporary inconvenience.';
     }
     $type = $this->request->getHeader('Content-Type');
     $mesg = $this->exception->getMessage();
     $file = $this->exception->getFile();
     $line = $this->exception->getLine();
     $code = $this->exception->getCode();
     $statusCode = method_exists($this->exception, 'getStatusCode') ? $this->exception->getStatusCode() : null;
     // Check status code is null
     if ($statusCode == null) {
         $statusCode = $code >= 100 && $code <= 500 ? $code : 400;
     }
     $this->response->withStatus($statusCode);
     // Check logger exist
     if ($this->logger !== null) {
         // Send error to log
         $this->logger->addError($this->exception->getMessage());
     }
     $this->isJson = isset($type[0]) && $type[0] == 'application/json';
     // Check content-type is application/json
     if ($this->isJson) {
         // Define content-type to json
         $this->response->withHeader('Content-Type', 'application/json');
         $error = ['status' => 'error', 'status_code' => $statusCode, 'error' => $title, 'details' => []];
         // Check debug
         if ($this->debug) {
             $error['details'] = ['message' => $mesg, 'file' => $file, 'line' => $line, 'code' => $code];
         }
         return $error;
     }
     // Define content-type to html
     $this->response->withHeader('Content-Type', 'text/html');
     $message = sprintf('<span>%s</span>', htmlentities($mesg));
     $error = ['type' => get_class($this->exception), $error['status_code'] = $statusCode, 'message' => $message];
     // Check debug
     if ($this->debug) {
         $trace = $this->exception->getTraceAsString();
         $trace = sprintf('<pre>%s</pre>', htmlentities($trace));
         $error['file'] = $file;
         $error['line'] = $line;
         $error['code'] = $code;
         $error['trace'] = $trace;
     }
     $error['debug'] = $this->debug;
     $error['title'] = $title;
     return $error;
 }
Example #4
0
 /**
  * Render the error page for the given object
  *
  * @param   \Throwable|\Exception  $error  The error object to be rendered
  *
  * @return  string
  *
  * @since   4.0
  */
 protected function doRender($error)
 {
     // Create our data object to be rendered
     $data = ['error' => true, 'code' => $error->getCode(), 'message' => $error->getMessage()];
     // Include the stack trace if in debug mode
     if (JDEBUG) {
         $data['trace'] = $error->getTraceAsString();
     }
     // Push the data object into the document
     $this->getDocument()->setBuffer(json_encode($data));
     if (ob_get_contents()) {
         ob_end_clean();
     }
     return $this->getDocument()->render();
 }
Example #5
0
 /**
  * @param \Exception|\Throwable $exception
  * @param \Spryker\Shared\EventJournal\Model\EventJournalInterface $eventJournal
  * @param \Spryker\Shared\NewRelic\ApiInterface $newRelicApi
  * @param bool $ignoreInternalExceptions
  *
  * @return void
  */
 protected static function sendExceptionToEventJournal($exception, EventJournalInterface $eventJournal, ApiInterface $newRelicApi, $ignoreInternalExceptions = false)
 {
     try {
         $event = new Event();
         $event->setField('message', $exception->getMessage());
         $event->setField('trace', $exception->getTraceAsString());
         $event->setField('class_name', get_class($exception));
         $event->setField('file_name', $exception->getFile());
         $event->setField('line', $exception->getLine());
         $event->setField(Event::FIELD_NAME, 'exception');
         self::addDeploymentInformation($event);
         $eventJournal->saveEvent($event);
     } catch (\Exception $internalException) {
         if (!$ignoreInternalExceptions) {
             self::sendExceptionToNewRelic($internalException, $eventJournal, $newRelicApi, true);
         }
     }
 }
Example #6
0
 /**
  * @param Exception|\Throwable $ex
  */
 private static function getErrorResponse($ex)
 {
     $debugTrace = $ex->getTraceAsString();
     $message = $ex->getMessage();
     $isHtmlMessage = method_exists($ex, 'isHtmlMessage') && $ex->isHtmlMessage();
     if (!$isHtmlMessage && Request::isApiRequest($_GET)) {
         $outputFormat = strtolower(Common::getRequestVar('format', 'xml', 'string', $_GET + $_POST));
         $response = new ResponseBuilder($outputFormat);
         return $response->getResponseException($ex);
     } elseif (!$isHtmlMessage) {
         $message = Common::sanitizeInputValue($message);
     }
     $logo = new CustomLogo();
     $logoHeaderUrl = false;
     $logoFaviconUrl = false;
     try {
         $logoHeaderUrl = $logo->getHeaderLogoUrl();
         $logoFaviconUrl = $logo->getPathUserFavicon();
     } catch (Exception $ex) {
         try {
             Log::debug($ex);
         } catch (\Exception $otherEx) {
             // DI container may not be setup at this point
         }
     }
     $result = Piwik_GetErrorMessagePage($message, $debugTrace, true, true, $logoHeaderUrl, $logoFaviconUrl);
     try {
         /**
          * Triggered before a Piwik error page is displayed to the user.
          *
          * This event can be used to modify the content of the error page that is displayed when
          * an exception is caught.
          *
          * @param string &$result The HTML of the error page.
          * @param Exception $ex The Exception displayed in the error page.
          */
         Piwik::postEvent('FrontController.modifyErrorPage', array(&$result, $ex));
     } catch (ContainerDoesNotExistException $ex) {
         // this can happen when an error occurs before the Piwik environment is created
     }
     return $result;
 }
Example #7
0
 /**
  * Render the error page for the given object
  *
  * @param   \Throwable|\Exception  $error  The error object to be rendered
  *
  * @return  string
  *
  * @since   4.0
  */
 protected function doRender($error)
 {
     // Create our data object to be rendered
     $xw = new \XMLWriter();
     $xw->openMemory();
     $xw->setIndent(true);
     $xw->setIndentString("\t");
     $xw->startDocument('1.0', 'UTF-8');
     $xw->startElement('error');
     $xw->writeElement('code', $error->getCode());
     $xw->writeElement('message', $error->getMessage());
     // Include the stack trace if in debug mode
     if (JDEBUG) {
         $xw->writeElement('trace', $error->getTraceAsString());
     }
     // End error element
     $xw->endElement();
     // Push the data object into the document
     $this->getDocument()->setBuffer($xw->outputMemory(true));
     if (ob_get_contents()) {
         ob_end_clean();
     }
     return $this->getDocument()->render();
 }
Example #8
0
 /**
  * @param Exception|\Throwable $exception
  * @return string
  */
 private function formatExceptionMessage($exception)
 {
     $message = $exception->getMessage();
     if (\Piwik_ShouldPrintBackTraceWithMessage()) {
         $message .= "\n" . $exception->getTraceAsString();
     }
     return Renderer::formatValueXml($message);
 }
Example #9
0
File: Logger.php Project: eix/core
 public function exception(\Throwable $throwable)
 {
     try {
         if (@Application::getSettings()->logging->exceptions) {
             $this->error('[EXCEPTION] ' . $throwable . PHP_EOL . $throwable->getTraceAsString());
         }
     } catch (SettingsException $throwable) {
         // No setting present, throwable will not be logged.
     }
 }
Example #10
0
 /**
  * @param \Throwable $exception
  *
  * @return array
  */
 protected function exceptionStackTrace(\Throwable $exception) : array
 {
     $return = [];
     $line = $exception->getLine();
     $file = $exception->getFile();
     $trace = $exception->getTrace();
     foreach (explode("\n", $exception->getTraceAsString()) as $currentLine) {
         $row = explode(' ', $currentLine);
         $stack = ['file' => null];
         $buffer = null;
         $index = trim(array_shift($row), '#');
         foreach ($row as $current) {
             // current file
             if (is_null($stack['file'])) {
                 if (substr($current, -1) === ':') {
                     $stack['file'] = trim($buffer ? $buffer . $current : $current, ':');
                     if (preg_match('`([^\\(]+)\\(([0-9]+)\\)`', $stack['file'], $matches)) {
                         $stack['file'] = $matches[1];
                         $stack['line'] = (int) $matches[2];
                     }
                 } else {
                     $buffer .= $current . ' ';
                 }
             } elseif (!isset($stack['function'])) {
                 $stack['function'] = strstr($current, '(', true);
                 $explodeString = strpos($stack['function'], '::') !== false ? '::' : '->';
                 $explode = explode($explodeString, $stack['function']);
                 if (sizeof($explode) > 1) {
                     $stack['class'] = $explode[0];
                     $stack['type'] = $explodeString;
                     $stack['function'] = $explode[1];
                     if (strpos($stack['class'], '\\') !== false) {
                         $explode = explode('\\', $stack['class']);
                         $stack['class'] = array_pop($explode);
                         $stack['namespace'] = implode('\\', $explode);
                     }
                 } elseif (strpos($stack['function'], '\\') !== false) {
                     $explode = explode('\\', $stack['function']);
                     $stack['function'] = array_pop($explode);
                     $stack['namespace'] = implode('\\', $explode);
                 }
                 $stack['args'] = strstr($current, '(') . ' ';
             } else {
                 $stack['args'] .= $current . ' ';
             }
         }
         if (is_null($stack['file'])) {
             $stack['file'] = $row[0];
         }
         $skip = false;
         // hack to hide error handler
         if (isset($stack['namespace']) && isset($stack['class'])) {
             if ($stack['namespace'] == 'Cawa\\Error' && $stack['class'] == 'Handler') {
                 $skip = true;
             }
         }
         // hack to hide backtrace call
         if (isset($stack['function']) && $stack['function'] == 'backtrace') {
             $skip = true;
             $file = $stack['file'];
             $line = (int) $stack['line'];
         }
         if ($skip == false) {
             if (isset($trace[$index]) && isset($trace[$index]['args'])) {
                 $stack['fullargs'] = $trace[$index]['args'];
             }
             $return[] = $stack;
         }
     }
     $return[0]['line'] = $line;
     $return[0]['file'] = $file;
     return $return;
 }
Example #11
0
 public static function buildStackTraceString(\Throwable $t)
 {
     return '#t ' . $t->getFile() . ' (' . $t->getLine() . ')' . "\r\n" . $t->getTraceAsString();
 }
Example #12
0
 private function getTrace() : string
 {
     return '<pre>' . $this->throwable->getTraceAsString() . '</pre>';
 }
Example #13
0
File: mail.php Project: pnixx/boot
 /**
  * Обработка ошибки
  * @param Throwable $e
  * @return mixed
  */
 public static function onException($e)
 {
     if (APPLICATION_ENV == 'production' && ($e->getCode() >= 500 || $e->getCode() == 0) && isset(Boot::getInstance()->config->mail->error)) {
         self::send(Boot::getInstance()->config->mail->error, "Error", "<pre>Error " . $e->getCode() . ": " . $e->getMessage() . "\r\n" . $e->getTraceAsString() . "SERVER:\r\n" . var_export($_SERVER, true) . "POST:\r\n" . var_export($_POST, true) . "</pre>");
     }
 }
Example #14
0
 /**
  * @param \Throwable|\Exception $e
  */
 private function printException($e)
 {
     echo 'Exception: ' . $e->getMessage() . ' (' . $e->getFile() . ':' . $e->getLine() . ")\n";
     echo $e->getTraceAsString() . "\n";
 }
 /**
  * Method that returns a response in the request format
  *
  * @todo Customize according to project
  * @param string $message Error message
  * @param int $status Status code
  * @param \Exception $exception Exception caught
  * @return JsonResponse|HtmlResponse
  */
 public function getResponseFormat($message, $status, \Throwable $exception)
 {
     if (count($this->accept) > 0 && $this->accept[0] == 'application/json') {
         $data = ['status' => $status, 'error' => ['msg' => $message]];
         if ($this->debug) {
             $data['error']['debug']['msg'] = $exception->getMessage();
             $data['error']['debug']['file'] = $exception->getFile();
             $data['error']['debug']['line'] = $exception->getLine();
             $data['error']['debug']['trace'] = $exception->getTrace();
         }
         return new JsonResponse($data, $status);
     }
     $msg = $message;
     if ($this->debug) {
         $msg .= '<br />Description: ' . $exception->getMessage();
         $msg .= '<br />File: ' . $exception->getFile();
         $msg .= '<br />Line: ' . $exception->getLine();
         $msg .= '<br />Trace: ' . $exception->getTraceAsString();
     }
     return new HtmlResponse($msg, $status);
 }
Example #16
0
 /**
  * @param Exception|Throwable $e
  */
 private static function reportOutageHTML($e)
 {
     global $wgShowDBErrorBacktrace, $wgShowHostnames, $wgShowSQLErrors;
     $sorry = htmlspecialchars(self::msg('dberr-problems', 'Sorry! This site is experiencing technical difficulties.'));
     $again = htmlspecialchars(self::msg('dberr-again', 'Try waiting a few minutes and reloading.'));
     if ($wgShowHostnames || $wgShowSQLErrors) {
         $info = str_replace('$1', Html::element('span', ['dir' => 'ltr'], htmlspecialchars($e->getMessage())), htmlspecialchars(self::msg('dberr-info', '($1)')));
     } else {
         $info = htmlspecialchars(self::msg('dberr-info-hidden', '(Cannot access the database)'));
     }
     MessageCache::singleton()->disable();
     // no DB access
     $html = "<h1>{$sorry}</h1><p>{$again}</p><p><small>{$info}</small></p>";
     if ($wgShowDBErrorBacktrace) {
         $html .= '<p>Backtrace:</p><pre>' . htmlspecialchars($e->getTraceAsString()) . '</pre>';
     }
     $html .= '<hr />';
     $html .= self::googleSearchForm();
     echo $html;
 }
Example #17
0
 /**
  * @param \Exception|\Throwable $e
  * @throws TerminateException
  */
 private function handleException($e)
 {
     $this->log("Exited with ERROR:", 'red');
     $this->log($e->getMessage(), 'red');
     echo $e->getTraceAsString() . PHP_EOL;
     $this->terminate(255);
 }
Example #18
0
File: log.php Project: pnixx/boot
 /**
  * Обработка ошибки
  * @param Throwable $e
  * @return mixed
  */
 public static function onException($e)
 {
     if (APPLICATION_ENV == 'production' && $e->getCode() != 404) {
         self::log("error.log", "Error " . $e->getCode() . ": " . $e->getMessage() . "\r\n" . $e->getTraceAsString());
     }
 }
Example #19
0
File: debug.php Project: pnixx/boot
 /**
  * Обработка ошибки
  * @param Throwable $e
  * @return mixed
  */
 public static function onException($e)
 {
     Boot::getInstance()->debug("  Message: " . $e->getMessage() . "" . PHP_EOL . $e->getTraceAsString());
 }
 /**
  * creates response body with useful data for display
  *
  * @param   \Throwable  $exception  the uncatched exception
  * @return  string
  */
 protected function createResponseBody(\Throwable $exception) : string
 {
     return $exception->getMessage() . "\nTrace:\n" . $exception->getTraceAsString();
 }
Example #21
0
/**
 * @param   Throwable  $ex  The Exception / Error being handled
 */
function akeeba_exception_handler($ex)
{
    echo "\n\n";
    echo "********** ERROR! **********\n\n";
    echo $ex->getMessage();
    echo "\n\nTechnical information:\n\n";
    echo "Code: " . $ex->getCode() . "\n";
    echo "File: " . $ex->getFile() . "\n";
    echo "Line: " . $ex->getLine() . "\n";
    echo "\nStack Trace:\n\n" . $ex->getTraceAsString();
    die("\n\n");
}
Example #22
0
 /**
  * QP框架异常处理方式
  *
  * @param   \Exception|\Throwable   $ex
  */
 public function fatalHandler($ex)
 {
     if (Config::getEnv("app.debug")) {
         echo "<pre>";
         echo "Exception : ", $ex->getMessage(), "<br>";
         echo "Catch position : " . $ex->getFile() . " : " . $ex->getLine() . "<br><br>";
         echo $ex->getTraceAsString();
     } else {
         echo strval(Config::getEnv("app.prod_tip"));
     }
     exit;
 }