Пример #1
2
 public function handleErrorException(\ErrorException $exception)
 {
     $message = sprintf('%s: %s in %s:%d', $this->errorCodeName($exception->getCode()), $exception->getMessage(), $exception->getFile(), $exception->getLine());
     $exception_trace = $exception->getTraceAsString();
     $exception_trace = substr($exception_trace, strpos($exception_trace, PHP_EOL) + 1);
     $message .= PHP_EOL . $exception_trace;
     $this->save($message);
 }
Пример #2
0
 /** @test */
 public function it_alllows_errors_to_be_arrays()
 {
     $errors = [['message' => 'Error', 'path' => '/foo']];
     $exception = new ErrorException($errors, 'Error', 100);
     $this->assertSame(400, $exception->getStatusCode());
     $this->assertJsonStringEqualsJsonString(json_encode(['message' => 'Error', 'logref' => 100, '_embedded' => ['errors' => [['message' => 'Error', 'path' => '/foo']]]]), $exception->getHal()->asJson());
 }
Пример #3
0
 public static function catch($e)
 {
     while (ob_get_level()) {
         $buf = ob_get_clean();
     }
     if (is_int($e)) {
         $args = func_get_args();
         $e = new \ErrorException($args[1], $args[0], 1, $args[2], $args[3]);
     }
     $type = self::$codes[$e->getCode()] ?? '';
     $title = "{$type}: " . self::message($e);
     $file = $e->getFile();
     $line = $e->getLine();
     $trace = $e->getTrace();
     if (preg_match('/view\\/Engine.* eval/', $file)) {
         $idx = $trace[0]['function'] === 'eval' ? 1 : 0;
         $file = $trace[$idx]['args'][2];
         $code = self::preview($trace[$idx]['args'][0], $line);
     } elseif (is_file($file)) {
         $code = self::preview(file_get_contents($file), $line);
     }
     $trace = self::trace($e);
     include 'exception/template.php';
     exit;
 }
Пример #4
0
 /**
  * @param \ErrorException $exception
  *
  * @return bool
  */
 protected function handleErrorException(\ErrorException $exception)
 {
     switch ($exception->getSeverity()) {
         case E_ERROR:
         case E_RECOVERABLE_ERROR:
         case E_CORE_ERROR:
         case E_COMPILE_ERROR:
         case E_USER_ERROR:
         case E_PARSE:
             $this->logger->error($this->buildLogMessage($exception));
             break;
         case E_WARNING:
         case E_USER_WARNING:
         case E_CORE_WARNING:
         case E_COMPILE_WARNING:
             $this->logger->warning($this->buildLogMessage($exception));
             break;
         case E_NOTICE:
         case E_USER_NOTICE:
             $this->logger->notice($this->buildLogMessage($exception));
             break;
         case E_STRICT:
         case E_DEPRECATED:
         case E_USER_DEPRECATED:
             $this->logger->info($this->buildLogMessage($exception));
             break;
     }
     return true;
 }
Пример #5
0
 public function handleErrors(\ErrorException $e)
 {
     $severity = $this->determineSeverityTextValue($e->getSeverity());
     $type = 'Error (' . $severity . ')';
     $message = $e->getMessage();
     $file = $e->getFile();
     $line = $e->getLine();
     return $this->getHtml($type, $message, $file, $line);
 }
Пример #6
0
 public function handleErrors(\ErrorException $e)
 {
     $severity = $this->determineSeverityTextValue($e->getSeverity());
     $message = $e->getMessage();
     $file = $e->getFile();
     $line = $e->getLine();
     $error = ['message' => $message, 'severity' => $severity, 'file' => $file, 'line' => $line];
     return $error;
 }
Пример #7
0
 static function handle($code, $message, $file, $line, $context)
 {
     echo "\n" . static::$codeMap[$code] . ': ' . $message . "\n";
     echo "#0 " . $file . '(' . $line . ")\n";
     $exception = new ErrorException('', $code, 0, $file, $line);
     $trace = $exception->getTraceAsString();
     $trace = preg_replace('~^.*?\\n|\\n.*?$~', '', $trace);
     echo $trace . "\n";
     return true;
 }
Пример #8
0
 public function handleErrors(\ErrorException $e)
 {
     $errorString = "<strong>%s</strong>: %s in <strong>%s</strong> on line <strong>%d</strong>";
     $severity = $this->determineSeverityTextValue($e->getSeverity());
     $error = $e->getMessage();
     $file = $e->getFile();
     $line = $e->getLine();
     $error = sprintf($errorString, $severity, $error, $file, $line);
     return $this->getTable($error);
 }
Пример #9
0
 public function handleErrors(\ErrorException $e)
 {
     $errorString = "%s%s in %s on line %d\n";
     $severity = $this->determineSeverityTextValue($e->getSeverity());
     // Let's calculate the length of the box, and set the box border.
     $dashes = "\n+" . str_repeat('-', strlen($severity) + 2) . "+\n";
     $severity = $dashes . '| ' . strtoupper($severity) . " |" . $dashes;
     // Okay, now let's prep the message components.
     $error = $e->getMessage();
     $file = $e->getFile();
     $line = $e->getLine();
     $error = sprintf($errorString, $severity, $error, $file, $line);
     return $error;
 }
 public static function shutdownCheck()
 {
     //error_log("shutdown check");
     if ($error = error_get_last()) {
         if ($error['type'] == E_COMPILE_ERROR) {
             $exception = new ErrorException($error['message'], 0, $error['type'], $error['file'], $error['line']);
             if (strpos($exception->getMessage(), "Cannot redeclare class") !== false) {
                 //send email alerts for duplicate class declarations.. error already logged by php
                 $ErrorHandler = new ErrorHandler($exception);
                 $ErrorHandler->email_alert();
             }
         }
     }
     return;
 }
Пример #11
0
 /**
  * Constructor.
  *
  * @param string     $message  The Exception message to throw.
  * @param int        $code     The Exception code.
  * @param int        $severity The severity level of the exception.
  * @param string     $filename The filename where the exception is thrown.
  * @param int        $line     The line number where the exception is thrown.
  * @param \Exception $prev     The previous exception --- used for exception chaining.
  *
  * @throws ParseException Exception thrown with default message if none passed.
  */
 public function __construct(string $message = '', int $code = 0, int $severity = 1, string $filename = __FILE__, int $line = __LINE__, \Exception $prev = null)
 {
     if (!$message) {
         throw new $this('Unknown ' . get_class($this));
     }
     parent::__construct($message, $code, $severity, $filename, $line, $prev);
 }
Пример #12
0
 /**
  * Constructor
  *
  * @param string  The exception message
  * @param integer The exception code
  */
 public function __construct($message, $code, $severity, $filename, $lineno)
 {
     if (!$message) {
         throw new $this('Unknown ' . get_class($this));
     }
     parent::__construct($message, $code, $severity, $filename, $lineno);
 }
Пример #13
0
 /**
  * Constructs the exception.
  * @link http://php.net/manual/en/errorexception.construct.php
  * @param $message [optional]
  * @param $code [optional]
  * @param $severity [optional]
  * @param $filename [optional]
  * @param $lineno [optional]
  * @param $previous [optional]
  */
 public function __construct($message = '', $code = 0, $severity = 1, $filename = __FILE__, $lineno = __LINE__, \Exception $previous = null)
 {
     parent::__construct($message, $code, $severity, $filename, $lineno, $previous);
     if (function_exists('xdebug_get_function_stack')) {
         $phpCompatibleTrace = [];
         $trace = array_slice(array_reverse(xdebug_get_function_stack()), 3, -1);
         foreach ($trace as &$frame) {
             if (!isset($frame['function'])) {
                 $frame['function'] = 'unknown';
             }
             // XDebug < 2.1.1: http://bugs.xdebug.org/view.php?id=695
             if (!isset($frame['type']) || $frame['type'] === 'static') {
                 $frame['type'] = '::';
             } elseif ($frame['type'] === 'dynamic') {
                 $frame['type'] = '->';
             }
             // XDebug has a different key name
             if (isset($frame['params']) && !isset($frame['args'])) {
                 $frame['args'] = $frame['params'];
             }
             $phpCompatibleTrace[] = $frame;
         }
         $ref = new \ReflectionProperty('Exception', 'trace');
         $ref->setAccessible(true);
         $ref->setValue($this, $phpCompatibleTrace);
     }
 }
Пример #14
0
 /**
  * @param string $message
  * @param int|string $http_status
  * @param null $filename
  * @param null $lineno
  * @param \Exception $previous
  */
 public function __construct($message = '', $http_status = Response::STATUS_ERROR, $filename = null, $lineno = null, \Exception $previous = null)
 {
     $code = 0;
     $this->status = $http_status;
     switch ($this->status) {
         case Response::STATUS_BAD_REQUEST:
             $code = 1;
             break;
         case Response::STATUS_METHOD_NOT_ALLOWED:
             $code = 2;
             break;
         case Response::STATUS_ERROR:
             $code = 3;
             break;
     }
     $info = array();
     if (!empty($previous)) {
         $info[] = 'caught ' . get_class($previous);
     }
     if (!empty($filename)) {
         $info[] = 'in ' . $filename;
     }
     if (!empty($lineno)) {
         $info[] = 'at line ' . $lineno;
     }
     if (!empty($info)) {
         $this->full_message = $message . ' [' . join(' ', $info) . ']';
     } else {
         $this->full_message = $message;
     }
     parent::__construct($message, $code, 1, is_null($filename) ? __FILE__ : $filename, is_null($lineno) ? __LINE__ : $lineno, $previous);
 }
 public function __construct($required, $code = 0, $previous = null)
 {
     if (is_string($required)) {
         $required = array($required);
     }
     parent::__construct(sprintf('One or more of required ("%s") parameters is missing!', implode('", "', $required)), $code, $previous);
 }
Пример #16
0
 /**
  * Constructor
  *
  * @param int    $httpStatus HTTP code
  * @param string $message    messsage
  * @param int    $severity   severity
  *
  * @return void
  */
 public function __construct($message, $httpStatus = 200, array $info = array())
 {
     $trace = debug_backtrace();
     $filename = $trace[0]['file'];
     $lineno = $trace[0]['line'];
     parent::__construct($message, $httpStatus, 0, $filename, $lineno);
     $this->_info = $info;
 }
Пример #17
0
 public function append($k, $v = null, $ifRealAppend = 'throwError')
 {
     if ($this->dbClass == null) {
         throw new \ErrorException('thisWhere ended already');
     }
     if ($ifRealAppend === false) {
         return $this;
     }
     $bakTb = $this->dbClass->_tmpObj($this->forTable);
     if (empty($v) && is_array($v)) {
         if ($ifRealAppend === 'markEmptyArray') {
             $this->_emptyWhere[] = $k;
             return $this;
         } else {
             $err = new \ErrorException('empty Array was Found when build where');
             error_log($err->getMessage() . "\n" . $err->getTraceAsString());
             throw $err;
         }
     }
     if (is_array($k)) {
         foreach ($k as $i => $v) {
             if (is_numeric($i)) {
                 $this->append(null, $v);
             } else {
                 $this->append($i, $v);
             }
         }
     } elseif (is_null($k)) {
         if (is_scalar($v)) {
             $err = new \ErrorException();
             error_log("should avoid:where->append(null,'sql-statement')\n" . $err->getTraceAsString());
             $this->r[] = $v;
         } else {
             $tmp = trim($v->end());
             if (!empty($tmp)) {
                 $tmp = '(' . substr($tmp, 6) . ')';
             }
             $this->r[] = $tmp;
         }
     } else {
         $this->r[] = $this->conv($k, $v);
     }
     $this->dbClass->_tmpObj($bakTb);
     return $this;
 }
Пример #18
0
 public function __construct($message, $code, $severity, $filename, $lineno, $previous)
 {
     if ($previous instanceof Exception) {
         parent::__construct($message, $code, $severity, $filename, $lineno, $previous);
     } else {
         parent::__construct($message, $code, $severity, $filename, $lineno);
         $this->context = $previous;
     }
 }
Пример #19
0
 public function __toString()
 {
     if ($this->isWrote === false) {
         $this->isWrote = true;
         return $this->getMessage() . "[Sooh_Base_Error]" . $this->getTraceAsString();
     } else {
         return parent::__toString();
     }
 }
Пример #20
0
 /**
  * Constructor.
  *
  * @param array $arr The error array
  *
  * @codeCoverageIgnore
  */
 public function __construct(array $arr)
 {
     $message = isset($arr['message']) ? $arr['message'] : 'There was an error parsing the file';
     $code = isset($arr['code']) ? $arr['code'] : 0;
     $severity = isset($arr['type']) ? $arr['type'] : 1;
     $file = isset($arr['file']) ? $arr['file'] : __FILE__;
     $line = isset($arr['line']) ? $arr['line'] : __LINE__;
     $exception = isset($arr['exception']) ? $arr['exception'] : null;
     parent::__construct($message, $code, $severity, $file, $line, $exception);
 }
Пример #21
0
 /**
  * @param string|array $message [optional] The Exception message to throw.
  * @param int $code [optional] The Exception code.
  * @param int $severity [optional] The severity level of the exception.
  * @param string $filename [optional] The filename where the exception is thrown.
  * @param int $lineno [optional] The line number where the exception is thrown.
  * @param \Exception $previous [optional] The previous exception used for the exception chaining.
  */
 public function __construct($message = '', $code = 0, $severity = 1, $filename = __FILE__, $lineno = __LINE__, $previous = null)
 {
     if (empty($message)) {
         $message = static::getLangMessage($code);
     } elseif (is_array($message)) {
         $arReplace = $message;
         $message = static::getLangMessage($code, $arReplace);
     }
     parent::__construct($message, $code, $severity, $filename, $lineno, $previous);
 }
Пример #22
0
 /**
  * Constructor
  *
  * @param   array  $error
  * @return  void
  */
 public function __construct(array $error)
 {
     $message = $error['message'];
     $code = isset($error['code']) ? $error['code'] : 0;
     $severity = isset($error['type']) ? $error['type'] : 1;
     $filename = isset($error['file']) ? $error['file'] : __FILE__;
     $lineno = isset($error['line']) ? $error['line'] : __LINE__;
     $exception = isset($error['exception']) ? $error['exception'] : null;
     parent::__construct($message, $code, $severity, $filename, $lineno, $exception);
 }
Пример #23
0
 function __construct($message, $code = null, $severity = E_ERROR, $filename = null, $line = null, array $vars = array())
 {
     parent::__construct($message, $code, $severity, $filename, $line);
     $this->message = $message;
     $this->code = isset($this->codes[$code]) ? $this->codes[$code] : $code;
     $this->severity = $severity;
     $this->file = $filename;
     $this->line = $line;
     $this->vars = $vars;
     $this->logErrors();
 }
Пример #24
0
 public function __construct($message = '', $code = 0, $previous = null)
 {
     if (is_an_array($message)) {
         $error = Ar($message);
         $this->column = $error->column;
         $this->message = $error->message;
     } else {
         $this->column = '(column not set)';
     }
     return parent::__construct($this->message, $code, $previous);
 }
Пример #25
0
 /**
  * @param string $message
  * @param int $traceOffset
  */
 public function __construct($message = "", $traceOffset = 0)
 {
     parent::__construct($message);
     $trace = $this->getTrace();
     $current = $trace[$traceOffset];
     $trace = array_slice($trace, $traceOffset + 1);
     $this->setTrace($trace);
     if (isset($current['line'])) {
         $this->setLine($current['line']);
     }
     if (isset($current['file'])) {
         $this->setFile($current['file']);
     }
 }
Пример #26
0
 public function handleWrite()
 {
     $error = null;
     set_error_handler(function ($errno, $errstr, $errfile, $errline) use(&$error) {
         $error = array('message' => $errstr, 'number' => $errno, 'file' => $errfile, 'line' => $errline);
     });
     $sent = fwrite($this->stream, $this->data);
     restore_error_handler();
     // Only report errors if *nothing* could be sent.
     // Any hard (permanent) error will fail to send any data at all.
     // Sending excessive amounts of data will only flush *some* data and then
     // report a temporary error (EAGAIN) which we do not raise here in order
     // to keep the stream open for further tries to write.
     // Should this turn out to be a permanent error later, it will eventually
     // send *nothing* and we can detect this.
     if ($sent === 0 || $sent === false) {
         if ($error === null) {
             $error = new \RuntimeException('Send failed');
         } else {
             $error = new \ErrorException($error['message'], 0, $error['number'], $error['file'], $error['line']);
         }
         $this->emit('error', array(new \RuntimeException('Unable to write to stream: ' . $error->getMessage(), 0, $error), $this));
         return;
     }
     $exceeded = isset($this->data[$this->softLimit - 1]);
     $this->data = (string) substr($this->data, $sent);
     // buffer has been above limit and is now below limit
     if ($exceeded && !isset($this->data[$this->softLimit - 1])) {
         $this->emit('drain', array($this));
     }
     // buffer is now completely empty (and not closed already)
     if ($this->data === '' && $this->listening) {
         $this->loop->removeWriteStream($this->stream);
         $this->listening = false;
         $this->emit('full-drain', array($this));
     }
 }
Пример #27
0
 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());
 }
Пример #28
0
 public function __construct($message, $code, $severity, $filename, $lineno, $traceOffset = null, $traceArgs = true, array $trace = null)
 {
     parent::__construct($message, $code, $severity, $filename, $lineno);
     if (null !== $trace) {
         if (!$traceArgs) {
             foreach ($trace as &$frame) {
                 unset($frame['args'], $frame['this'], $frame);
             }
         }
         $this->setTrace($trace);
     } elseif (null !== $traceOffset) {
         if (function_exists('xdebug_get_function_stack')) {
             $trace = xdebug_get_function_stack();
             if (0 < $traceOffset) {
                 array_splice($trace, -$traceOffset);
             }
             foreach ($trace as &$frame) {
                 if (!isset($frame['type'])) {
                     // XDebug pre 2.1.1 doesn't currently set the call type key http://bugs.xdebug.org/view.php?id=695
                     if (isset($frame['class'])) {
                         $frame['type'] = '::';
                     }
                 } elseif ('dynamic' === $frame['type']) {
                     $frame['type'] = '->';
                 } elseif ('static' === $frame['type']) {
                     $frame['type'] = '::';
                 }
                 // XDebug also has a different name for the parameters array
                 if (!$traceArgs) {
                     unset($frame['params'], $frame['args']);
                 } elseif (isset($frame['params']) && !isset($frame['args'])) {
                     $frame['args'] = $frame['params'];
                     unset($frame['params']);
                 }
             }
             unset($frame);
             $trace = array_reverse($trace);
         } elseif (function_exists('symfony_debug_backtrace')) {
             $trace = symfony_debug_backtrace();
             if (0 < $traceOffset) {
                 array_splice($trace, 0, $traceOffset);
             }
         } else {
             $trace = array();
         }
         $this->setTrace($trace);
     }
 }
Пример #29
0
 /**
  * ConnectionException constructor.
  *
  * @param Request $request
  * @param int $message
  * @param int $code
  * @param \Throwable $previous
  */
 public function __construct(Request $request, string $message, int $code = null, \Throwable $previous = null)
 {
     $this->request = $request;
     $message = sprintf('[%s %s] [ERROR %s] ', $request->getMethod(), $request->getUri()->get(false, false), $code) . htmlspecialchars($message);
     $filename = __FILE__;
     $lineno = __LINE__;
     $debug = debug_backtrace(DEBUG_BACKTRACE_IGNORE_ARGS);
     foreach ($debug as $index => $backtrace) {
         if (isset($backtrace['class']) && stripos($backtrace['class'], 'Cawa\\HttpClient\\') !== false && (empty($debug[$index + 1]['class']) || !empty($debug[$index + 1]['class']) && stripos($debug[$index + 1]['class'], 'Cawa\\HttpClient\\') === false)) {
             $filename = $debug[$index]['file'];
             $lineno = $debug[$index]['line'];
             break;
         }
     }
     parent::__construct($message, $code, 1, $filename, $lineno, $previous);
 }
Пример #30
0
 /**
  * constructor method which always needs to be called to stack errors for error
  * output dumping/logging and call the parent constructor to set all error arguments
  * because only parent constructor of phps native Exception class can set instance
  * properties. the class constructor expects the same arguments as its parent or instead
  * of passing a message string in first parameter can be called with an instance of
  * exception. in this case the arguments of passed instances are compared with the
  * constructor arguments to determine which will be passed to parent constructor.
  * the instance will be passed
  *
  * @error 10501
  * @param string|object $mixed expects any of the above described values (string or instance of Exception)
  * @param int $code expects optional error code
  * @param int $severity expects optional severity level
  * @param null|string $file expects the file name where exception was created
  * @param null|int $line expects the line where exception was created
  */
 public function __construct($mixed = "", $code = 0, $severity = XAPP_ERROR_ERROR, $file = null, $line = null)
 {
     if (is_object($mixed)) {
         if ($mixed instanceof ErrorException) {
             $severity = (int) $severity > (int) $mixed->getSeverity() ? (int) $severity : (int) $mixed->getSeverity();
         }
         parent::__construct($mixed->getMessage(), (int) $code > (int) $mixed->getCode() ? (int) $code : (int) $mixed->getCode(), (int) $severity, (string) $mixed->getFile(), (int) $mixed->getLine());
     } else {
         if ($file !== null && $line !== null) {
             parent::__construct((string) $mixed, (int) $code, (int) $severity, (string) $file, (int) $line);
         } else {
             parent::__construct((string) $mixed, (int) $code, (int) $severity);
         }
     }
     if ($severity !== -1) {
         self::stack($this);
     }
 }