private function baseCrash() { global $lastExceptionError, $lastError; if (isset($lastExceptionError)) { $error = $lastExceptionError; } else { $error = (array) error_get_last(); $error["trace"] = @getTrace(3); $errorConversion = [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"]; $error["fullFile"] = $error["file"]; $error["file"] = cleanPath($error["file"]); $error["type"] = isset($errorConversion[$error["type"]]) ? $errorConversion[$error["type"]] : $error["type"]; if (($pos = strpos($error["message"], "\n")) !== false) { $error["message"] = substr($error["message"], 0, $pos); } } if (isset($lastError)) { $this->data["lastError"] = $lastError; } $this->data["error"] = $error; unset($this->data["error"]["fullFile"]); unset($this->data["error"]["trace"]); $this->addLine("Error: " . $error["message"]); $this->addLine("File: " . $error["file"]); $this->addLine("Line: " . $error["line"]); $this->addLine("Type: " . $error["type"]); if (strpos($error["file"], "src/BukkitPE/") === false and strpos($error["file"], "src/raklib/") === false and file_exists($error["fullFile"])) { $this->addLine(); $this->addLine("THIS CRASH WAS CAUSED BY A PLUGIN"); $this->data["plugin"] = true; $reflection = new \ReflectionClass(PluginBase::class); $file = $reflection->getProperty("file"); $file->setAccessible(true); foreach ($this->server->getPluginManager()->getPlugins() as $plugin) { $filePath = \BukkitPE\cleanPath($file->getValue($plugin)); if (strpos($error["file"], $filePath) === 0) { $this->data["plugin"] = $plugin->getName(); $this->addLine("BAD PLUGIN: " . $plugin->getDescription()->getFullName()); break; } } } else { $this->data["plugin"] = false; } $this->addLine(); $this->addLine("Code:"); $this->data["code"] = []; if ($this->server->getProperty("auto-report.send-code", true) !== false) { $file = @file($error["fullFile"], FILE_IGNORE_NEW_LINES); for ($l = max(0, $error["line"] - 10); $l < $error["line"] + 10; ++$l) { $this->addLine("[" . ($l + 1) . "] " . @$file[$l]); $this->data["code"][$l + 1] = @$file[$l]; } } $this->addLine(); $this->addLine("Backtrace:"); foreach ($this->data["trace"] = $error["trace"] as $line) { $this->addLine($line); } $this->addLine(); }
public function logException(\Exception $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 = \BukkitPE\cleanPath($errfile); $this->log($type, get_class($e) . ": \"{$errstr}\" ({$errno}) in \"{$errfile}\" at line {$errline}"); foreach (@\BukkitPE\getTrace(1, $trace) as $i => $line) { $this->debug($line); } }