/**
  * Writes exception to different logs
  *
  * @param \Exception|\Throwable $exception The exception(PHP 5.x) or throwable(PHP >= 7.0) object.
  * @param string $context The context where the exception was thrown, WEB or CLI
  * @return void
  * @see \TYPO3\CMS\Core\Utility\GeneralUtility::sysLog(), \TYPO3\CMS\Core\Utility\GeneralUtility::devLog()
  * @TODO #72293 This will change to \Throwable only if we are >= PHP7.0 only
  */
 protected function writeLogEntries($exception, $context)
 {
     // Do not write any logs for this message to avoid filling up tables or files with illegal requests
     if ($exception->getCode() === 1396795884) {
         return;
     }
     $filePathAndName = $exception->getFile();
     $exceptionCodeNumber = $exception->getCode() > 0 ? '#' . $exception->getCode() . ': ' : '';
     $logTitle = 'Core: Exception handler (' . $context . ')';
     $logMessage = 'Uncaught TYPO3 Exception: ' . $exceptionCodeNumber . $exception->getMessage() . ' | ' . get_class($exception) . ' thrown in file ' . $filePathAndName . ' in line ' . $exception->getLine();
     if ($context === 'WEB') {
         $logMessage .= '. Requested URL: ' . GeneralUtility::getIndpEnv('TYPO3_REQUEST_URL');
     }
     $backtrace = $exception->getTrace();
     // Write error message to the configured syslogs
     GeneralUtility::sysLog($logMessage, $logTitle, GeneralUtility::SYSLOG_SEVERITY_FATAL);
     // When database credentials are wrong, the exception is probably
     // caused by this. Therefor we cannot do any database operation,
     // otherwise this will lead into recurring exceptions.
     try {
         // Write error message to devlog
         // see: $TYPO3_CONF_VARS['SYS']['enable_exceptionDLOG']
         if (TYPO3_EXCEPTION_DLOG) {
             GeneralUtility::devLog($logMessage, $logTitle, 3, array('TYPO3_MODE' => TYPO3_MODE, 'backtrace' => $backtrace));
         }
         // Write error message to sys_log table
         $this->writeLog($logTitle . ': ' . $logMessage);
     } catch (\Exception $exception) {
     }
 }
Exemple #2
1
 public static function exceptionHandle(Exception $exception)
 {
     if (DEBUG_MODE) {
         //直接输出调试信息
         echo nl2br($exception->__toString());
         echo '<hr /><p>Router:</p><pre>';
         print_r(Singleton::getInstance('Router'));
         echo '</pre>';
     } else {
         $code = $exception->getCode();
         $message = nl2br($exception->getMessage());
         /*
                     如果错误码"可能为"合法的http状态码则尝试设置,
                     setStatus()方法会忽略非法的http状态码. */
         if ($code >= 400 && $code <= 505 && !headers_sent()) {
             ResponseModule::setStatus($code);
         }
         $var_list = array('message' => $message, 'code' => $code, 'file' => $exception->getFile(), 'url' => Singleton::getInstance('Router')->getUrl());
         if ($error_file = self::_getErrorFilePath($code)) {
             Lugit::$view = new View($var_list);
             Lugit::$view->render($error_file);
         } else {
             echo 'No error page is found.<pre>';
             print_r($var_list);
             echo '</pre>';
         }
     }
     exit;
 }
 /**
  * If detailed errors are enabled, just format the exception into
  * a simple error message and display it.
  *
  * @param \Exception $exception
  *
  * @return string
  */
 public static function format(\Exception $exception)
 {
     if (Sapi::isCli()) {
         return "+++ Untreated Exception +++" . PHP_EOL . "Message: " . $exception->getMessage() . PHP_EOL . "Location: " . $exception->getFile() . " on line " . $exception->getLine() . PHP_EOL . "Stack Trace: " . PHP_EOL . $exception->getTraceAsString() . PHP_EOL;
     }
     return "<html><h2>Untreated Exception</h2>\n      <h3>Message:</h3>\n      <pre>" . $exception->getMessage() . "</pre>\n      <h3>Location:</h3>\n      <pre>" . $exception->getFile() . " on line " . $exception->getLine() . "</pre>\n      <h3>Stack Trace:</h3>\n      <pre>" . $exception->getTraceAsString() . "</pre></html>";
 }
Exemple #4
0
 /**
  * Show exception screen
  *
  * @param \Exception $exception
  */
 public function showException(\Exception $exception)
 {
     @ob_end_clean();
     $msg = sprintf("%s\nFile: %s\nLine: %d\nTrace:\n%s", $exception->getMessage(), $exception->getFile(), $exception->getLine(), $exception->getTraceAsString());
     \Kalibri::logger()->add(Logger::L_EXCEPTION, $msg);
     $viewName = \Kalibri::config()->get('error.view.exception');
     if ($viewName) {
         $view = new \Kalibri\View($viewName);
         $view->ex = $exception;
         $str = '';
         $file = \fopen($exception->getFile(), 'r');
         for ($i = 0; $i < $exception->getLine() - 16; $i++) {
             \fgets($file);
         }
         for ($i = 0; $i < 20; $i++) {
             $str .= \fgets($file);
         }
         $view->code = Highlight::php($str, true, 1, $exception->getLine());
         if ($view->isExists()) {
             $view->render();
         } else {
             // Fallback to show any message in case if exception view not found or not set
             echo "<h1>Exception</h1><p>{$exception->getMessage()}</p>";
         }
     }
     exit;
 }
Exemple #5
0
 /**
  * Filters stack frames from PHPUnit classes.
  *
  * @param  Exception $e
  * @param  boolean   $asString
  * @return string
  */
 public static function getFilteredStacktrace(Exception $e, $asString = TRUE)
 {
     if (!defined('PHPUNIT_TESTSUITE')) {
         $blacklist = PHPUnit_Util_GlobalState::phpunitFiles();
     } else {
         $blacklist = array();
     }
     if ($asString === TRUE) {
         $filteredStacktrace = '';
     } else {
         $filteredStacktrace = array();
     }
     if ($e instanceof PHPUnit_Framework_SyntheticError) {
         $eTrace = $e->getSyntheticTrace();
     } else {
         $eTrace = $e->getTrace();
     }
     if (!self::frameExists($eTrace, $e->getFile(), $e->getLine())) {
         array_unshift($eTrace, array('file' => $e->getFile(), 'line' => $e->getLine()));
     }
     foreach ($eTrace as $frame) {
         if (isset($frame['file']) && is_file($frame['file']) && !isset($blacklist[$frame['file']])) {
             if ($asString === TRUE) {
                 $filteredStacktrace .= sprintf("%s:%s\n", $frame['file'], isset($frame['line']) ? $frame['line'] : '?');
             } else {
                 $filteredStacktrace[] = $frame;
             }
         }
     }
     return $filteredStacktrace;
 }
 /**
  * If detailed errors are enabled, just format the exception into
  * a simple error message and display it.
  *
  * @param \Exception $exception
  * @param boolean    $isCli
  *
  * @return string
  */
 public static function format(\Exception $exception, $isCli = false)
 {
     if ($isCli === true) {
         return "+++ Untreated Exception +++" . PHP_EOL . "Message: " . $exception->getMessage() . PHP_EOL . "Location: " . $exception->getFile() . " on line " . $exception->getLine() . PHP_EOL . "Stack Trace: " . PHP_EOL . $exception->getTraceAsString() . PHP_EOL;
     }
     return "<html>\n    <head>\n      <style>\n        pre { display: block;\n            padding: 8.5px;\n            margin: 0 0 9px;\n            line-height: 18px;\n            word-break: break-all;\n            word-wrap: break-word;\n            white-space: pre;\n            white-space: pre-wrap;\n            border: 1px solid #ccc;\n            border: 1px solid rgba(0, 0, 0, 0.15);\n            -webkit-border-radius: 4px;\n            -moz-border-radius: 4px;\n            border-radius: 6px;\n            color: chartreuse;\n            background-color: black;\n        }\n      </style>\n    </head>\n      <h2>Untreated Exception</h2>\n      <h3>Message:</h3>\n      <pre>" . $exception->getMessage() . "</pre>\n      <h3>Location:</h3>\n      <pre>" . $exception->getFile() . " on line " . $exception->getLine() . "</pre>\n      <h3>Stack Trace:</h3>\n      <pre>" . $exception->getTraceAsString() . "</pre></html>";
 }
Exemple #7
0
 /**
  * Function must be public to call on caused exceptions
  * 
  * @param  array
  * @return string
  */
 function getCauseMessage(&$causes)
 {
     $trace = $this->getTrace();
     $cause = array('class' => get_class($this), 'message' => $this->getMessage(), 'file' => 'unknown', 'line' => 'unknown');
     if (isset($trace[0])) {
         if (isset($trace[0]['file'])) {
             $cause['file'] = $trace[0]['file'];
             $cause['line'] = $trace[0]['line'];
         }
     }
     $causes[] = $cause;
     if ($this->cause instanceof Exception) {
         $this->cause->getCauseMessage($causes);
     } elseif ($this->cause instanceof Exception) {
         $causes[] = array('class' => get_class($this->cause), 'message' => $this->cause->getMessage(), 'file' => $this->cause->getFile(), 'line' => $this->cause->getLine());
     }
     if (is_array($this->cause)) {
         foreach ($this->cause as $cause) {
             if ($cause instanceof Exception || $cause instanceof Exception) {
                 $cause->getCauseMessage($causes);
             } elseif ($cause instanceof Exception) {
                 $causes[] = array('class' => get_class($cause), 'message' => $cause->getMessage(), 'file' => $cause->getFile(), 'line' => $cause->getLine());
             } elseif (is_array($cause) && isset($cause['message'])) {
                 // PEAR_ErrorStack warning
                 $causes[] = array('class' => $cause['package'], 'message' => $cause['message'], 'file' => isset($cause['context']['file']) ? $cause['context']['file'] : 'unknown', 'line' => isset($cause['context']['line']) ? $cause['context']['line'] : 'unknown');
             } else {
                 $causes[] = array('class' => null, 'message' => $cause, 'file' => null, 'line' => null);
             }
         }
     }
 }
Exemple #8
0
 /**
  * Filters stack frames from PHPUnit classes.
  *
  * @param  Exception $e
  * @param  boolean   $filterTests
  * @param  boolean   $asString
  * @return string
  */
 public static function getFilteredStacktrace(Exception $e, $filterTests = TRUE, $asString = TRUE)
 {
     if ($asString === TRUE) {
         $filteredStacktrace = '';
     } else {
         $filteredStacktrace = array();
     }
     $groups = array('DEFAULT');
     if (!defined('PHPUNIT_TESTSUITE')) {
         $groups[] = 'PHPUNIT';
     }
     if ($filterTests) {
         $groups[] = 'TESTS';
     }
     $eTrace = $e->getTrace();
     if (!self::frameExists($eTrace, $e->getFile(), $e->getLine())) {
         array_unshift($eTrace, array('file' => $e->getFile(), 'line' => $e->getLine()));
     }
     foreach ($eTrace as $frame) {
         if (isset($frame['file']) && is_file($frame['file']) && !PHP_CodeCoverage::getInstance()->filter()->isFiltered($frame['file'], $groups, TRUE)) {
             if ($asString === TRUE) {
                 $filteredStacktrace .= sprintf("%s:%s\n", $frame['file'], isset($frame['line']) ? $frame['line'] : '?');
             } else {
                 $filteredStacktrace[] = $frame;
             }
         }
     }
     return $filteredStacktrace;
 }
Exemple #9
0
 /**
  * @param \Exception $objEx
  */
 public function push(\Exception $objEx)
 {
     $this->errorStackTraces[] = ['code' => $objEx->getCode(), 'file' => $objEx->getFile(), 'line' => $objEx->getLine(), 'msg' => $objEx->getMessage(), 'string' => $objEx->getTraceAsString()];
     if ($this->versionType === 'dev') {
         print sprintf('Exception in %s, line %s with message %s', $objEx->getFile(), $objEx->getLine(), $objEx->getMessage());
     }
 }
 /**
  * Get a backtrace for an exception.
  *
  * Optionally limit the number of rows to include with $count, and exclude
  * Psy from the trace.
  *
  * @param \Exception $e          The exception with a backtrace.
  * @param int        $count      (default: PHP_INT_MAX)
  * @param bool       $includePsy (default: true)
  *
  * @return array Formatted stacktrace lines.
  */
 protected function getBacktrace(\Exception $e, $count = null, $includePsy = true)
 {
     if ($cwd = getcwd()) {
         $cwd = rtrim($cwd, DIRECTORY_SEPARATOR) . DIRECTORY_SEPARATOR;
     }
     if ($count === null) {
         $count = PHP_INT_MAX;
     }
     $lines = array();
     $trace = $e->getTrace();
     array_unshift($trace, array('function' => '', 'file' => $e->getFile() !== null ? $e->getFile() : 'n/a', 'line' => $e->getLine() !== null ? $e->getLine() : 'n/a', 'args' => array()));
     if (!$includePsy) {
         for ($i = count($trace) - 1; $i >= 0; $i--) {
             $thing = isset($trace[$i]['class']) ? $trace[$i]['class'] : $trace[$i]['function'];
             if (preg_match('/\\\\?Psy\\\\/', $thing)) {
                 $trace = array_slice($trace, $i + 1);
                 break;
             }
         }
     }
     for ($i = 0, $count = min($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']) ? $this->replaceCwd($cwd, $trace[$i]['file']) : 'n/a';
         $line = isset($trace[$i]['line']) ? $trace[$i]['line'] : 'n/a';
         $lines[] = sprintf(' <class>%s</class>%s%s() at <info>%s:%s</info>', OutputFormatter::escape($class), OutputFormatter::escape($type), OutputFormatter::escape($function), OutputFormatter::escape($file), OutputFormatter::escape($line));
     }
     return $lines;
 }
Exemple #11
0
 /**
  * Get a backtrace for an exception.
  *
  * Optionally limit the number of rows to include with $count, and exclude
  * Psy from the trace.
  *
  * @param \Exception $e          The exception with a backtrace.
  * @param int        $count      (default: PHP_INT_MAX)
  * @param bool       $includePsy (default: true)
  *
  * @return array Formatted stacktrace lines.
  */
 protected function getBacktrace(\Exception $e, $count = null, $includePsy = true)
 {
     if ($count === null) {
         $count = PHP_INT_MAX;
     }
     $lines = array();
     $trace = $e->getTrace();
     array_unshift($trace, array('function' => '', 'file' => $e->getFile() != null ? $e->getFile() : 'n/a', 'line' => $e->getLine() != null ? $e->getLine() : 'n/a', 'args' => array()));
     if (!$includePsy) {
         for ($i = count($trace) - 1; $i >= 0; $i--) {
             $thing = isset($trace[$i]['class']) ? $trace[$i]['class'] : $trace[$i]['function'];
             if (preg_match('/\\\\?Psy\\\\/', $thing)) {
                 $trace = array_slice($trace, $i + 1);
                 break;
             }
         }
     }
     for ($i = 0, $count = min($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';
         $lines[] = sprintf(' %s%s%s() at <info>%s:%s</info>', $class, $type, $function, $file, $line);
     }
     return $lines;
 }
Exemple #12
0
/**
 * @param \Exception $e
 * @return bool
 */
function exceptionHandler(\Exception $e)
{
    echo '<h1>Error</h1><p>Sorry, the script died with a exception</p>';
    echo $e->getMessage() . ' in <br>' . $e->getFile() . ': <br>' . $e->getLine(), ' : <br>', __FUNCTION__, ' : <br>', $e->getTraceAsString();
    log::error($e->getMessage() . ' in ' . $e->getFile() . ':' . $e->getLine() . "<br>\n", "Code: " . $e->getCode(), $e->getTrace());
    mail(ADMIN_MAIL, '[GitReminder] System got locked', $e->getMessage() . ' in ' . $e->getFile() . ':' . $e->getLine() . "\n\n" . "Funktion -> " . __FUNCTION__ . $e->getTraceAsString() . "\n\n" . "Code: " . $e->getCode());
    @trigger_error('', E_USER_ERROR);
}
 public function handleException(Exception $exception)
 {
     $msg = "Uncaught Exception: " . $exception->getMessage() . "\n";
     $msg .= $exception->getMessage() . "\n";
     $msg .= 'Line: ' . $exception->getLine() . " in " . $exception->getFile();
     $msg .= "\n\nTrace Summary:\n" . self::traceFormat($exception->getTrace());
     if (ERROR_DISPLAY_MODE == 'html') {
         $msg .= "\nFull Trace: \n" . print_r($exception->getTrace(), 1);
     }
     $this->show($msg, $exception->getFile(), $exception->getLine(), $exception->getCode(), 'E_WARNING');
 }
Exemple #14
0
 /**
  * Logs the original exception message.
  *
  * Provided as a manual override over the default `WP_DEBUG` dependent behaviour.
  *
  * @see Tribe__Exception::handle()
  *
  * @return bool  `true` if the message was logged, `false` otherwise.
  */
 private function log_original_exception_message()
 {
     if (!class_exists('Tribe__Log')) {
         return false;
     }
     $logger = new Tribe__Log();
     $message = $this->original_exception->getMessage();
     $log_type = $this->get_log_type_for_exception_code($this->original_exception->getCode());
     $src = $this->original_exception->getFile() . ':' . $this->original_exception->getLine();
     $logger->log($message, $log_type, $src);
     return true;
 }
 /**
  * @description Build message
  *
  * @return string
  */
 public function exceptionMessage()
 {
     $msg = '';
     if ($this->exception->getCode()) {
         $msg .= "Exception code: " . $this->exception->getCode() . PHP_EOL;
     }
     $msg .= $this->exception->getMessage() . PHP_EOL;
     $msg .= "At file: " . $this->exception->getFile();
     $msg .= ": " . $this->exception->getLine() . PHP_EOL;
     $msg .= "Trace: " . PHP_EOL . $this->exception->getTraceAsString();
     return $msg;
 }
 /**
  * Display errors in development and email them in release mode
  *
  * @param Exception $e
  * @param array $a_additional_info
  */
 public function Publish(Exception $e, array $a_additional_info)
 {
     // define an assoc array of error string
     // in reality the only entries we should
     // consider are E_WARNING, E_NOTICE, E_USER_ERROR,
     // E_USER_WARNING and E_USER_NOTICE
     $error_types = array(E_ERROR => 'Error', E_WARNING => 'Warning', E_PARSE => 'Parsing Error', E_NOTICE => 'Notice', E_CORE_ERROR => 'Core Error', E_CORE_WARNING => 'Core Warning', E_COMPILE_ERROR => 'Compile Error', E_COMPILE_WARNING => 'Compile Warning', E_USER_ERROR => 'User Error', E_USER_WARNING => 'User Warning', E_USER_NOTICE => 'User Notice');
     if (defined('E_STRICT')) {
         $error_types[E_STRICT] = 'Runtime Notice';
     }
     if (defined('E_RECOVERABLE_ERROR')) {
         $error_types[E_RECOVERABLE_ERROR] = 'Catchable Fatal Error';
     }
     # Build up information about the error
     $body = $e->getMessage() . "\n\n";
     if (!stristr($e->getFile(), 'exception-manager.class')) {
         $body .= $e->getFile() . ', line ' . $e->getLine() . "\n\n";
     }
     $trace = $e->getTraceAsString();
     if ($trace) {
         $body .= $trace . "\n\n";
     }
     if (array_key_exists($e->getCode(), $error_types)) {
         $body .= 'Code: ' . $error_types[$e->getCode()] . "\n";
     }
     # Get details of anything in additional_info
     ob_start();
     var_dump($a_additional_info);
     $body .= ob_get_contents();
     ob_end_clean();
     # What's the context?
     if ($_SERVER['REQUEST_METHOD'] == 'POST') {
         foreach ($_POST as $key => $value) {
             $body .= '$POST[\'' . $key . '\']: ' . $value . "\n";
         }
     } else {
         foreach ($_GET as $key => $value) {
             $body .= '$GET[\'' . $key . '\']: ' . $value . "\n";
         }
     }
     foreach ($_SERVER as $key => $value) {
         $body .= '$SERVER[\'' . $key . '\']: ' . $value . "\n";
     }
     require_once 'Zend/Mail.php';
     $email = new Zend_Mail('UTF-8');
     $email->addTo($this->emailAddress);
     $email->setFrom('errors@' . $_SERVER['HTTP_HOST'], 'errors@' . $_SERVER['HTTP_HOST']);
     $email->setSubject('Error: ' . $e->getMessage());
     $email->setBodyText($body);
     $email->send();
 }
 /**
  * {@inheritdoc}
  */
 protected function render()
 {
     global $argv;
     $message = $this->exception->getMessage();
     $file = $this->exception->getFile();
     $line = $this->exception->getLine();
     $code = $this->exception->getCode();
     $command = implode(" ", $argv);
     $this->printText("<<6>>{$message}\n\n");
     $this->printText("<<3>>File    : <<0>>{$file}\n");
     $this->printText("<<3>>Line    : <<0>>{$line}\n");
     $this->printText("<<3>>Code    : <<0>>{$code}\n");
     $this->printText("<<3>>Command : <<0>>{$command}\n");
 }
Exemple #18
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;
 }
 /**
  * @param array $testClassSuperTypes
  * @param \Exception $e
  * @param \ReflectionClass $class
  * @return array
  */
 public static function findFileAndLineOfFailureOrError(array $testClassSuperTypes, \Exception $e, \ReflectionClass $class)
 {
     if (in_array($class->getName(), $testClassSuperTypes)) {
         return;
     }
     if ($e->getFile() == $class->getFileName()) {
         return array($e->getFile(), $e->getLine());
     }
     foreach ($e->getTrace() as $trace) {
         if (array_key_exists('file', $trace) && $trace['file'] == $class->getFileName()) {
             return array($trace['file'], $trace['line']);
         }
     }
     return self::findFileAndLineOfFailureOrError($testClassSuperTypes, $e, $class->getParentClass());
 }
/**
 * Vangt alle onopgevangen exception op
 *
 * @param Exception $exception de exception
 */
function exception_handler($exception)
{
    $error = "<em>" . $exception->getMessage() . "</em><br/>(line " . $exception->getLine() . " in " . $exception->getFile() . ")";
    try {
        $user = "";
        if (isset($_SESSION['userid'])) {
            $user = new User($_SESSION['userid']);
            $user = $user->getGebruikersnaam();
        }
        new Error("", $exception->getMessage(), $exception->getFile(), $exception->getLine(), $user);
    } catch (Exception $e) {
        //doe niets anders is er een oneindige error lus :(
    }
    showError($error);
}
 /**
  * @param \Exception $e
  * @param bool $terminate
  */
 public function exception(\Exception $e, $terminate = true)
 {
     $html_message = '';
     $id = hash('md4', $e->getMessage() . $e->getFile() . $e->getLine());
     if (!$e instanceof \ErrorException) {
         $html_message = '<strong>- Uncaught exception: </strong> ' . get_class($e) . "<br />\n";
     }
     $html_message .= '<strong>- Message:</strong> ' . $e->getMessage();
     if ($this->mode == 'development') {
         $html_message .= "<br />\n<strong>- File:</strong> " . $e->getFile() . "<br />\n<strong>- Line:</strong> " . $e->getLine() . "<br />\n<strong>- Code:</strong> " . $e->getCode();
     }
     $html_message .= "<br />\n<strong>- ID:</strong> {$id}";
     $log_body = trim(strip_tags($html_message));
     // If we're in production/test the html message will not
     // contain info about the file where the error appeared
     // therefor we add it to error log here
     if ($this->mode != 'development') {
         $log_body .= "\n- File: " . $e->getFile() . "\n- Line: " . $e->getLine() . "\n- Code: " . $e->getCode();
     }
     $log_message = '### Error ' . (empty($_SERVER['REQUEST_URI']) ? '' : $_SERVER['REQUEST_URI']) . (empty($_SERVER['REQUEST_METHOD']) ? '' : ' (' . $_SERVER['REQUEST_METHOD'] . ')') . (empty($_SERVER['REMOTE_ADDR']) ? '' : ' ' . $_SERVER['REMOTE_ADDR']) . "\n" . $log_body . "\n" . $e->getTraceAsString();
     if ($this->mode == 'development') {
         $html_message .= "\n<p>" . nl2br($e->getTraceAsString()) . "</p>\n";
     } else {
         $html_message .= "\n<p><em>Stack trace and full error message available in the error log</em></p>\n";
     }
     $html_message = '<h2>PHP Error</h2>' . $html_message;
     error_log($log_message);
     if ($terminate) {
         if (!headers_sent()) {
             header('HTTP/1.1 500 Internal Server Error');
         }
         echo $html_message;
         die;
     }
 }
Exemple #22
0
 /**
  * new exception
  * @param  Exception $exception
  * @param  boolean   $printError show error or not
  * @param  boolean   $clear       clear the errorlog
  * @param  string    $errorFile  file to save to
  */
 public static function newMessage(\Exception $exception)
 {
     $message = $exception->getMessage();
     $code = $exception->getCode();
     $file = $exception->getFile();
     $line = $exception->getLine();
     $trace = $exception->getTraceAsString();
     $date = date('Y-m-d H:i:s');
     $logMessage = "<h3>Exception information:</h3>\n\n           <p><strong>Date:</strong> {$date}</p>\n\n           <p><strong>Message:</strong> {$message}</p>\n\n           <p><strong>Code:</strong> {$code}</p>\n\n           <p><strong>File:</strong> {$file}</p>\n\n           <p><strong>Line:</strong> {$line}</p>\n\n           <h3>Stack trace:</h3>\n\n           <pre>{$trace}</pre>\n\n           <hr />\n";
     if (is_file(self::$errorFile) === false) {
         file_put_contents(self::$errorFile, '');
     }
     if (self::$clear) {
         $f = fopen(self::$errorFile, "r+");
         if ($f !== false) {
             ftruncate($f, 0);
             fclose($f);
         }
         $content = null;
     } else {
         $content = file_get_contents(self::$errorFile);
     }
     file_put_contents(self::$errorFile, $logMessage . $content);
     //send email
     if (MAIL_ERROR === true) {
         self::sendEmail($logMessage);
     }
 }
 /**
  * Обработчик исключений
  * @param Exception $exeption Исключение
  */
 public function exceptionHandler(Exception $exeption)
 {
     $message = $exeption->getMessage();
     $file = $exeption->getFile();
     $line = $exeption->getLine();
     $this->console("Exception: '{$message}' in file {$file}:{$line}");
 }
Exemple #24
0
 public static function gerarLogException(\Exception $ex)
 {
     $msg = " - " . $ex->getMessage();
     $msg .= " [Arquivo: " . $ex->getFile();
     $msg .= " - Linha: " . $ex->getLine() . " ]";
     return $msg;
 }
Exemple #25
0
 public static function log_writer(\Exception $exception, $clear = false, $error_file = 'ex_log.html')
 {
     $message = $exception->getMessage();
     $code = $exception->getCode();
     $file = $exception->getFile();
     $line = $exception->getLine();
     $trace = $exception->getTraceAsString();
     $date = date('M d, Y h:iA');
     $log_message = "<h3>Exception information:</h3>\n\t\t<p>\n\t\t<strong>Date:</strong> {$date}\n\t\t</p>\n\n\t\t<p>\n\t\t<strong>Message:</strong> {$message}\n\t\t</p>\n\t\t\t\n\t\t<p>\n\t\t<strong>Code:</strong> {$code}\n\t\t</p>\n\n\t\t<p>\n\t\t<strong>File:</strong> {$file}\n\t\t</p>\n\n\t\t<p>\n\t\t<strong>Line:</strong> {$line}\n\t\t</p>\n\n\t\t<h3>Stack trace:</h3>\n\t\t<pre>{$trace}</pre>\n\t\t\n\t\t<h3>Request information:</h3>\n\t\t<pre>";
     foreach ($_REQUEST as $key => $value) {
         $log_message .= "<strong>{$key}</strong>: {$value}<br/>";
     }
     $log_message .= "</pre>";
     $log_message .= "<h3>Server information:</h3>\n\t\t<pre>";
     foreach ($_SERVER as $key => $value) {
         $log_message .= "<strong>{$key}</strong>: {$value}<br/>";
     }
     $log_message .= "</pre>\n\t\t<br />\n\t\t<hr /><br /><br />";
     if (is_file($error_file) === false) {
         file_put_contents($error_file, '');
     }
     if ($clear) {
         $content = '';
     } else {
         $content = file_get_contents($error_file);
     }
     file_put_contents($error_file, $log_message . $content);
 }
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";
                }
            }
        }
    }
}
Exemple #27
0
 public function logException(Exception $exception, $order_id, $type, $line_nuber = '')
 {
     $message = $exception->getMessage();
     $code = $exception->getCode();
     $file = $exception->getFile();
     $line = $exception->getLine();
     $trace = $exception->getTraceAsString();
     $date = date('M d, Y h:iA');
     if ($type == 'order') {
         $log_message = "<p><strong>Order Id:</strong> {$order_id}\r\n\t\t    <p><strong>Error Message:</strong> {$message}</p>\r\n            <p><strong>Line Number:</strong> {$line_nuber}</p>";
     } else {
         if ($type == 'invoice') {
             $log_message = "<p><strong>Invoice Error : </strong></p>\r\n\t\t    <p><strong>Order Id:</strong> {$order_id}</p>\r\n            <p><strong>Error Message:</strong> {$message}</p>";
         } else {
             if ($type == 'shipment') {
                 $log_message = "<p><strong>Shipment Error : </strong></p>\r\n\t\t    <p><strong>Order Id:</strong> {$order_id}</p>\r\n            <p><strong>Error Message:</strong> {$message}</p>";
             } else {
                 if ($type == 'creditmemo') {
                     $log_message = "<p><strong>Creditmemo Error : </strong></p>\r\n\t\t    <p><strong>Order Id:</strong> {$order_id}</p>\r\n            <p><strong>Error Message:</strong> {$message}</p>";
                 }
             }
         }
     }
     if (is_file($this->error_file) === false) {
         file_put_contents($this->error_file, '');
     }
     $content = file_get_contents($this->error_file);
     file_put_contents($this->error_file, $content . $log_message);
 }
 /**
  * Render response body
  * @param array $env
  * @param Exception $exception
  * @return string
  */
 protected function renderBody(&$env, $exception)
 {
     $title = 'Slim Application Error';
     $code = $exception->getCode();
     $message = $exception->getMessage();
     $file = $exception->getFile();
     $line = $exception->getLine();
     $trace = $exception->getTraceAsString();
     $html = sprintf('<h1>%s</h1>', $title);
     $html .= '<p>The application could not run because of the following error:</p>';
     $html .= '<h2>Details</h2>';
     if ($code) {
         $html .= sprintf('<div><strong>Code:</strong> %s</div>', $code);
     }
     if ($message) {
         $html .= sprintf('<div><strong>Message:</strong> %s</div>', $message);
     }
     if ($file) {
         $html .= sprintf('<div><strong>File:</strong> %s</div>', $file);
     }
     if ($line) {
         $html .= sprintf('<div><strong>Line:</strong> %s</div>', $line);
     }
     if ($trace) {
         $html .= '<h2>Trace</h2>';
         $html .= sprintf('<pre>%s</pre>', $trace);
     }
     return sprintf("<html><head><title>%s</title><style>body{margin:0;padding:30px;font:12px/1.5 Helvetica,Arial,Verdana,sans-serif;}h1{margin:0;font-size:48px;font-weight:normal;line-height:48px;}strong{display:inline-block;width:65px;}</style></head><body>%s</body></html>", $title, $html);
 }
Exemple #29
0
 public static function handle_exception(Exception $e)
 {
     echo "<div class='error'>{Exception handler}" . PHP_EOL . "[" . $e->getCode() . "] " . $e->getMessage() . "<br />" . PHP_EOL;
     echo "Line [" . $e->getLine() . "] in file [" . $e->getFile() . "]<br />" . PHP_EOL . $e->getTraceAsString() . "<br />" . PHP_EOL;
     echo "</div>" . PHP_EOL;
     return true;
 }
 public function getHtml()
 {
     $html = '<div style="padding:20px;border-radius:20px;background:#EEE;text-align:center;border:1px solid #BBB;height:50px;font-family: monospace;">';
     $html .= '    <h1 style="padding:0;margin:0 0 -10px 0;font-size:20px;">Error: ' . parent::getMessage() . '</h1>';
     $html .= '    <p style="font-size: smaller">In ' . parent::getFile() . ' In ' . parent::getLine() . '</p>';
     $html .= '</div>';
     $html .= '<br/>';
     $html .= '<div style="padding: 20px 25px 30px 25px;border-radius:20px;background:#FFF;text-align:left;border:1px solid #BBB;font-family: monospace;">';
     $html .= '    <h1 style="padding:0;margin:0;font-size: 20px;">Stack Trace</h1>';
     $html .= '    <ul>';
     foreach (parent::getTrace() as $key => $trace) {
         $args = [];
         foreach ($trace['args'] as $arg) {
             if (empty($args)) {
                 $args[] = '\'\'';
             } else {
                 $args[] = '\'' . $arg . '\'';
             }
         }
         $html .= '        <li style="list-style: none;clear: both;">';
         $html .= '            <div style="float:left;margin-right: 10px;color: #9A9A9A;background-color: rgba(232, 232, 232, 0.29);width: 40px;margin-left: -40px;margin-right: 40px;text-align: right;">' . ($key + 1) . '.</div>';
         $html .= '            <div style="float:left;margin-right: 10px;">' . $trace['file'] . '(' . $trace['line'] . ')</div>';
         $html .= '            <div style="float:left">' . $trace['class'] . $trace['type'] . 'setPassword(' . implode(', ', $args) . ')</div>';
         $html .= '        </li>';
     }
     $html .= '     </ul>';
     $html .= '</div>';
     return $html;
 }