Example #1
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 #2
0
 public function friendlyExceptionHandler(\Throwable $exception)
 {
     $message = $exception->getMessage();
     $file = $exception->getFile();
     $line = $exception->getLine();
     //
     $obLevel = ob_get_level();
     if ($obLevel > 0) {
         ob_end_clean();
     }
     if (self::$_isActive) {
         echo $message;
         return;
     }
     self::$_isActive = true;
     // Log Messages
     error_log("Exception: " . $message . " in {$file} on line {$line}");
     $html = '<html lang="' . $this->_htmlLang . '"><head><meta charset="UTF-8"><title>' . $this->_escapeString($message) . '</title></head><body>';
     $html .= '<table width="100%" height="100%"><tr><td><table width="50%" border="0" align="center" cellpadding="4" cellspacing="1" bgcolor="#cccccc">';
     $html .= '<tr bgcolor="#dddddd"><td height="40">' . $this->_tableTitle . '</td></tr><tr bgcolor="#ffffff"><td height="150" align="center">';
     $html .= $this->_escapeString($message);
     $html .= '</td></tr><tr bgcolor="#f2f2f2"><td height="40" align="center"><a href="/">' . $this->_backText . '</a></td></tr></table>';
     $html .= '</td></tr><tr><td height="35%"></td></tr></table></body></html>';
     echo $html;
     self::$_isActive = false;
     //
     return true;
 }
 /**
  * Display the given exception to the user.
  *
  * @param  \Exception  $exception
  * @return \Symfony\Component\HttpFoundation\Response
  */
 public function display(\Throwable $exception)
 {
     if ($this->returnJson) {
         return new JsonResponse(array('error' => $exception->getMessage(), 'file' => $exception->getFile(), 'line' => $exception->getLine()), 500);
     }
     return $this->symfony->createResponse($exception);
 }
 /**
  * @inheritDoc
  */
 public function __construct(\Throwable $t)
 {
     $this->message = $t->getMessage();
     $this->code = $t->getCode();
     $this->file = $t->getFile();
     $this->line = $t->getLine();
 }
Example #5
0
 /**
  * Shorthand: Logs the given Exception.
  *
  * @param Throwable|Exception $exception The Exception to log
  */
 public static function logException($exception)
 {
     if ($exception instanceof ErrorException) {
         self::logError($exception->getSeverity(), $exception->getMessage(), $exception->getFile(), $exception->getLine());
     } else {
         $logger = self::factory();
         $logger->log(get_class($exception), $exception->getMessage(), [], $exception->getFile(), $exception->getLine());
     }
 }
Example #6
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'));
     }
 }
 /**
  * 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 #9
0
 /**
  * @param \Throwable $exception
  */
 public static function exceptionHandler(\Throwable $exception)
 {
     // This error code is not included in error_reporting
     if (!error_reporting() || $exception->getLine() == 0) {
         return;
     }
     $output = new ConsoleOutput(OutputInterface::VERBOSITY_VERY_VERBOSE);
     if (!$exception instanceof \Exception) {
         $exception = new \ErrorException($exception->getMessage(), $exception->getCode(), 0, $exception->getFile(), $exception->getLine(), $exception);
         self::$application->renderException($exception, $output);
     } else {
         self::$application->renderException($exception, $output);
     }
 }
 public function __construct(\Throwable $e)
 {
     if ($e instanceof \ParseError) {
         $message = 'Parse error: ' . $e->getMessage();
         $severity = E_PARSE;
     } elseif ($e instanceof \TypeError) {
         $message = 'Type error: ' . $e->getMessage();
         $severity = E_RECOVERABLE_ERROR;
     } else {
         $message = $e->getMessage();
         $severity = E_ERROR;
     }
     \ErrorException::__construct($message, $e->getCode(), $severity, $e->getFile(), $e->getLine());
     $this->setTrace($e->getTrace());
 }
Example #11
0
 /**
  * 记录起始请求日志
  * 记录成功返回true,失败或没记录日志返回false
  *
  * @param  \Exception|\Throwable   $ex
  * @return  bool
  */
 public static function error_log($ex)
 {
     if (!BaseLog::isLog('error')) {
         return false;
     }
     if (!Config::getEnv("app.framework_error_log")) {
         return false;
     }
     $data = Request::nonPostParam();
     if (Config::getEnv("app.request_log_post")) {
         $data = Request::param();
     }
     $log_msg = "\r\nQP->Main最外层捕捉到Exception异常:\r\n请求参数:{Param}\r\n异常信息:{E_Msg}\r\n异常位置:{E_Point}\r\n更多异常队列信息:{E_Trace}\r\n";
     $log_data = ['Param' => json_encode($data), 'E_Msg' => $ex->getMessage(), 'E_Point' => $ex->getFile() . ":" . $ex->getLine(), 'E_Trace' => json_encode($ex->getTrace())];
     return Log::error($log_msg, $log_data, true, 'framework');
 }
Example #12
0
 public function exceptionHandler(\Throwable $exception)
 {
     $message = $exception->getMessage();
     $values = $exception->getTrace();
     $traces = [];
     $trace = new Trace();
     $trace->setFile($exception->getFile());
     $trace->setLine($exception->getLine());
     $trace->setClass(get_class($exception));
     $traces[] = $trace;
     foreach ($values as $value) {
         $trace = new Trace();
         $trace->setFile($this->getArrayValue($value, "file"));
         $trace->setLine($this->getArrayValue($value, "line"));
         $trace->setFunction($this->getArrayValue($value, "function"));
         $trace->setClass($this->getArrayValue($value, "class"));
         $traces[] = $trace;
     }
     $this->log($message, $traces);
 }
Example #13
0
 /**
  * @param \Throwable $t
  * @throws \Comely\Framework\KernelException
  * @throws \Comely\KnitException
  */
 public function send(\Throwable $t)
 {
     $knit = (new Knit())->setTemplatePath(__DIR__)->setCompilerPath($this->kernel->getDisk("cache"));
     // Extract information from \Throwable
     $error = ["message" => null, "method" => null, "code" => $t->getCode(), "file" => $t->getFile(), "line" => $t->getLine(), "trace" => []];
     // Check if exception has "getTranslated" method
     $error["message"] = method_exists($t, "getTranslated") ? $t->getTranslated() : $t->getMessage();
     // Check if exception is child of ComelyException
     if (method_exists($t, "getMethod") && is_subclass_of($t, "ComelyException")) {
         $error["method"] = $t->getMethod();
         $error["source"] = "Component";
     } else {
         $error["method"] = get_class($t);
         $error["source"] = "Caught";
     }
     // Populate Trace
     foreach ($t->getTrace() as $trace) {
         if (Arrays::hasKeys($trace, ["function", "file", "line"])) {
             $trace["method"] = $trace["function"];
             if (isset($trace["class"])) {
                 $trace["method"] = $trace["class"] . $trace["type"] . $trace["function"];
             }
             $error["trace"][] = $trace;
         }
     }
     // Config
     $config = $this->kernel->config()->getNode("app");
     $display = ["backtrace" => $config["errorHandler"]["screen"]["debugBacktrace"] ?? false, "triggered" => $config["errorHandler"]["screen"]["triggeredErrors"] ?? false, "paths" => $config["errorHandler"]["screen"]["completePaths"] ?? false];
     // Assign values
     $knit->assign("display", $display);
     $knit->assign("error", $error);
     $knit->assign("triggered", $this->kernel->errorHandler()->fetchAll());
     $knit->assign("version", ["comely" => \Comely::VERSION, "kernel" => Kernel::VERSION, "framework" => Kernel::VERSION, "knit" => Knit::VERSION]);
     // Prepare template
     $screen = $knit->prepare("screen.knit");
     $screen = str_replace("%%knit-timer%%", number_format($screen->getTimer(), 6, ".", ""), $screen->getOutput());
     exit($screen);
 }
Example #14
0
 /**
  * Decodes an exception and retrieves the correct caller.
  *
  * @param \Exception|\Throwable $exception
  *   The exception object that was thrown.
  *
  * @return array
  *   An error in the format expected by _drupal_log_error().
  */
 public static function decodeException($exception)
 {
     $message = $exception->getMessage();
     $backtrace = $exception->getTrace();
     // Add the line throwing the exception to the backtrace.
     array_unshift($backtrace, array('line' => $exception->getLine(), 'file' => $exception->getFile()));
     // For PDOException errors, we try to return the initial caller,
     // skipping internal functions of the database layer.
     if ($exception instanceof \PDOException || $exception instanceof DatabaseExceptionWrapper) {
         // The first element in the stack is the call, the second element gives us
         // the caller. We skip calls that occurred in one of the classes of the
         // database layer or in one of its global functions.
         $db_functions = array('db_query', 'db_query_range');
         while (!empty($backtrace[1]) && ($caller = $backtrace[1]) && (isset($caller['class']) && (strpos($caller['class'], 'Query') !== FALSE || strpos($caller['class'], 'Database') !== FALSE || strpos($caller['class'], 'PDO') !== FALSE) || in_array($caller['function'], $db_functions))) {
             // We remove that call.
             array_shift($backtrace);
         }
         if (isset($exception->query_string, $exception->args)) {
             $message .= ": " . $exception->query_string . "; " . print_r($exception->args, TRUE);
         }
     }
     $caller = static::getLastCaller($backtrace);
     return array('%type' => get_class($exception), '@message' => $message, '%function' => $caller['function'], '%file' => $caller['file'], '%line' => $caller['line'], 'severity_level' => static::ERROR, 'backtrace' => $backtrace, '@backtrace_string' => $exception->getTraceAsString());
 }
Example #15
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;
 }
 /**
  * Prepare a response in case an error occurred.
  *
  * @param \Throwable $exception
  * @param Http\Response $response
  * @return void
  */
 protected function prepareErrorResponse($exception, Http\Response $response)
 {
     $pathPosition = strpos($exception->getFile(), 'Packages/');
     $filePathAndName = $pathPosition !== false ? substr($exception->getFile(), $pathPosition) : $exception->getFile();
     $exceptionCodeNumber = $exception->getCode() > 0 ? '#' . $exception->getCode() . ': ' : '';
     $content = PHP_EOL . 'Uncaught Exception in Flow ' . $exceptionCodeNumber . $exception->getMessage() . PHP_EOL;
     $content .= 'thrown in file ' . $filePathAndName . PHP_EOL;
     $content .= 'in line ' . $exception->getLine() . PHP_EOL . PHP_EOL;
     $content .= Debugger::getBacktraceCode($exception->getTrace(), false, true) . PHP_EOL;
     if ($exception instanceof Exception) {
         $statusCode = $exception->getStatusCode();
     } else {
         $statusCode = 500;
     }
     $response->setStatus($statusCode);
     $response->setContent($content);
     $response->setHeader('X-Flow-ExceptionCode', $exception->getCode());
     $response->setHeader('X-Flow-ExceptionMessage', $exception->getMessage());
 }
Example #17
0
 /**
  * @param \Throwable $exception
  *
  * @return bool
  */
 public static function exceptionHandler(\Throwable $exception)
 {
     // This error code is not included in error_reporting
     if (!error_reporting() || $exception->getLine() == 0) {
         return;
     }
     if ('cli' === PHP_SAPI || isset($_SERVER['HTTP_USER_AGENT']) && stripos($_SERVER['HTTP_USER_AGENT'], 'curl') !== false) {
         $formatterClass = '\\Cawa\\Error\\Formatter\\CliFormatter';
     } else {
         $formatterClass = '\\Cawa\\Error\\Formatter\\HtmlFormatter';
     }
     if (AbstractApp::isInit() && AbstractApp::instance() instanceof HttpApp) {
         self::log($exception);
         self::response()->setStatus(500);
         if (AbstractApp::env() != AbstractApp::PROD || Ip::isAdmin()) {
             $formatter = new $formatterClass();
             self::render($formatter, $exception);
         } else {
             self::clearAllBuffer();
             echo self::router()->returnError(500);
         }
         AbstractApp::instance()->end();
     } else {
         if (!headers_sent()) {
             header('HTTP/1.1 500 Internal Server Error');
         }
         if (AbstractApp::env() != AbstractApp::PROD) {
             $formatter = new $formatterClass();
             self::render($formatter, $exception);
         } else {
             self::clearAllBuffer();
             echo '<!DOCTYPE HTML PUBLIC "-//IETF//DTD HTML 2.0//EN">' . "\n" . '<html><head>' . "\n" . '<title>' . self::response()->getStatusString(500) . '</title>' . "\n" . '</head><body>' . "\n" . '<h1>' . self::response()->getStatusString(500) . '</h1>' . "\n" . '</body></html>';
         }
     }
 }
Example #18
0
 /**
  * @param \Throwable|\Exception $e
  */
 private function printException($e)
 {
     echo 'Exception: ' . $e->getMessage() . ' (' . $e->getFile() . ':' . $e->getLine() . ")\n";
     echo $e->getTraceAsString() . "\n";
 }
Example #19
0
/**
 * Convert an Exception or Error into an array (for logging)
 *
 * @param \Throwable $ex
 * @return array
 */
function throwableToArray(\Throwable $ex) : array
{
    $prev = $ex->getPrevious();
    return ['line' => $ex->getLine(), 'file' => $ex->getFile(), 'message' => $ex->getMessage(), 'code' => $ex->getCode(), 'trace' => $ex->getTrace(), 'previous' => $prev ? throwableToArray($prev) : null];
}
Example #20
0
function log_exception(Throwable $ex)
{
    log_error("\tException: " . $ex->getMessage() . PHP_EOL . "At " . $ex->getFile() . ":" . $ex->getLine());
}
Example #21
0
 public function logException(\Throwable $e, $trace = null)
 {
     if ($trace === null) {
         $trace = $e->getTrace();
     }
     $errstr = $e->getMessage();
     $errfile = $e->getFile();
     $errno = $e->getCode();
     $errline = $e->getLine();
     $errorConversion = [0 => "EXCEPTION", E_ERROR => "E_ERROR", E_WARNING => "E_WARNING", E_PARSE => "E_PARSE", E_NOTICE => "E_NOTICE", E_CORE_ERROR => "E_CORE_ERROR", E_CORE_WARNING => "E_CORE_WARNING", E_COMPILE_ERROR => "E_COMPILE_ERROR", E_COMPILE_WARNING => "E_COMPILE_WARNING", E_USER_ERROR => "E_USER_ERROR", E_USER_WARNING => "E_USER_WARNING", E_USER_NOTICE => "E_USER_NOTICE", E_STRICT => "E_STRICT", E_RECOVERABLE_ERROR => "E_RECOVERABLE_ERROR", E_DEPRECATED => "E_DEPRECATED", E_USER_DEPRECATED => "E_USER_DEPRECATED"];
     if ($errno === 0) {
         $type = LogLevel::CRITICAL;
     } else {
         $type = ($errno === E_ERROR or $errno === E_USER_ERROR) ? LogLevel::ERROR : (($errno === E_USER_WARNING or $errno === E_WARNING) ? LogLevel::WARNING : LogLevel::NOTICE);
     }
     $errno = isset($errorConversion[$errno]) ? $errorConversion[$errno] : $errno;
     if (($pos = strpos($errstr, "\n")) !== false) {
         $errstr = substr($errstr, 0, $pos);
     }
     $errfile = \pocketmine\cleanPath($errfile);
     $this->log($type, get_class($e) . ": \"{$errstr}\" ({$errno}) in \"{$errfile}\" at line {$errline}");
     foreach (@\pocketmine\getTrace(1, $trace) as $i => $line) {
         $this->debug($line);
     }
 }
Example #22
0
 public function exceptionHandler(\Throwable $e, $trace = null)
 {
     if ($e === null) {
         return;
     }
     global $lastError;
     if ($trace === null) {
         $trace = $e->getTrace();
     }
     $errstr = $e->getMessage();
     $errfile = $e->getFile();
     $errno = $e->getCode();
     $errline = $e->getLine();
     $type = ($errno === E_ERROR or $errno === E_USER_ERROR) ? \LogLevel::ERROR : (($errno === E_USER_WARNING or $errno === E_WARNING) ? \LogLevel::WARNING : \LogLevel::NOTICE);
     if (($pos = strpos($errstr, "\n")) !== false) {
         $errstr = substr($errstr, 0, $pos);
     }
     $errfile = cleanPath($errfile);
     if ($this->logger instanceof MainLogger) {
         $this->logger->logException($e, $trace);
     }
     $lastError = ["type" => $type, "message" => $errstr, "fullFile" => $e->getFile(), "file" => $errfile, "line" => $errline, "trace" => @getTrace(1, $trace)];
     global $lastExceptionError, $lastError;
     $lastExceptionError = $lastError;
     $this->crashDump();
 }
Example #23
0
 /**
  * @param Exception|\Throwable $e
  * @return Exception
  */
 private function decorateExceptionWithDebugTrace($e)
 {
     // If we are in tests, show full backtrace
     if (defined('PIWIK_PATH_TEST_TO_ROOT')) {
         if (\Piwik_ShouldPrintBackTraceWithMessage()) {
             $message = $e->getMessage() . " in \n " . $e->getFile() . ":" . $e->getLine() . " \n " . $e->getTraceAsString();
         } else {
             $message = $e->getMessage() . "\n \n --> To temporarily debug this error further, set const PIWIK_PRINT_ERROR_BACKTRACE=true; in index.php";
         }
         return new Exception($message);
     }
     return $e;
 }
Example #24
0
 /**
  * @param \Throwable|\Exception $exc
  * @return array
  */
 protected function build_exception_frames($exc)
 {
     $frames = array();
     foreach ($exc->getTrace() as $frame) {
         $framedata = array('filename' => isset($frame['file']) ? $frame['file'] : '<internal>', 'lineno' => isset($frame['line']) ? $frame['line'] : 0, 'method' => $frame['function']);
         if ($this->include_exception_code_context && isset($frame['file']) && isset($frame['line'])) {
             $this->add_frame_code_context($frame['file'], $frame['line'], $framedata);
         }
         $frames[] = $framedata;
     }
     // rollbar expects most recent call to be last, not first
     $frames = array_reverse($frames);
     // add top-level file and line to end of the reversed array
     $file = $exc->getFile();
     $line = $exc->getLine();
     $framedata = array('filename' => $file, 'lineno' => $line);
     if ($this->include_exception_code_context) {
         $this->add_frame_code_context($file, $line, $framedata);
     }
     $frames[] = $framedata;
     $this->shift_method($frames);
     return $frames;
 }
Example #25
0
 private function checkForTypeLoaderThrowable(\Throwable $throwable)
 {
     if (null !== ($tle = TypeLoader::getLatestException())) {
         TypeLoader::clear();
         if ($throwable instanceof \Error && ($throwable->getCode() === 0 || $throwable->getCode() === E_ERROR) && $throwable->getFile() === $tle->getFile() && $throwable->getLine() === $tle->getLine()) {
             return $tle;
         }
     }
     return $throwable;
 }
Example #26
0
 private function getFileinfo() : string
 {
     return '<p>in ' . $this->throwable->getFile() . ' (Line: ' . $this->throwable->getLine() . ')</p>';
 }
Example #27
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 #28
0
 /**
  * @param \Exception|\Throwable $exception
  *
  * @return string
  */
 private function formatExceptionFilePathWithLine($exception)
 {
     $options = 0;
     if (version_compare(PHP_VERSION, '5.4.0', '>=')) {
         $options = JSON_UNESCAPED_SLASHES | JSON_UNESCAPED_UNICODE;
     }
     $path = substr(json_encode($exception->getFile(), $options), 1, -1);
     return $path . ':' . $exception->getLine();
 }
 /**
  * Method run by PHP's exception handler
  * @param \Throwable $e
  */
 public function exceptionHandler(\Throwable $e)
 {
     if ($e instanceof \Error) {
         $this($e->getCode(), $e->getMessage(), $e->getFile(), $e->getLine());
         if ($this->rethrowException) {
             goto rethrow;
         }
     }
     rethrow:
     throw $e;
 }
Example #30
0
 private static function applyEnhancedCodeInfo(ThrowableInfo $throwableInfo, \Throwable $t)
 {
     if (null !== ($filePath = $t->getFile())) {
         $throwableInfo->addCodeInfo(self::createCodeInfo($t->getFile(), $t->getLine(), $t->getStartLine(), $t->getEndLine()));
     }
     foreach ($t->getAdditionalErrors() as $additionalError) {
         $throwableInfo->addCodeInfo(self::createCodeInfo($additionalError->getFilePath(), $additionalError->getLineNo(), $additionalError->getStartLineNo(), $additionalError->getEndLineNo(), $additionalError->getDescription()));
     }
 }