mirror of
https://github.com/pmmp/PocketMine-MP.git
synced 2025-06-07 12:18:46 +00:00
Catch uncatched thrown Exceptions to get useful backtraces
This commit is contained in:
parent
915443b508
commit
7fcaa78de4
@ -130,8 +130,11 @@ class CrashDump{
|
|||||||
}
|
}
|
||||||
|
|
||||||
private function baseCrash(){
|
private function baseCrash(){
|
||||||
global $lastError;
|
global $lastExceptionError, $lastError;
|
||||||
|
|
||||||
|
if(isset($lastExceptionError)){
|
||||||
|
$error = $lastExceptionError;
|
||||||
|
}else{
|
||||||
$error = (array) error_get_last();
|
$error = (array) error_get_last();
|
||||||
$error["trace"] = getTrace(4);
|
$error["trace"] = getTrace(4);
|
||||||
$errorConversion = array(
|
$errorConversion = array(
|
||||||
@ -157,6 +160,7 @@ class CrashDump{
|
|||||||
if(($pos = strpos($error["message"], "\n")) !== false){
|
if(($pos = strpos($error["message"], "\n")) !== false){
|
||||||
$error["message"] = substr($error["message"], 0, $pos);
|
$error["message"] = substr($error["message"], 0, $pos);
|
||||||
}
|
}
|
||||||
|
}
|
||||||
|
|
||||||
if(isset($lastError)){
|
if(isset($lastError)){
|
||||||
$this->data["lastError"] = $lastError;
|
$this->data["lastError"] = $lastError;
|
||||||
|
@ -172,13 +172,16 @@ namespace pocketmine {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
function getTrace($start = 1){
|
function getTrace($start = 1, $trace = null){
|
||||||
|
if($trace === null){
|
||||||
if(function_exists("xdebug_get_function_stack")){
|
if(function_exists("xdebug_get_function_stack")){
|
||||||
$trace = array_reverse(xdebug_get_function_stack());
|
$trace = array_reverse(xdebug_get_function_stack());
|
||||||
}else{
|
}else{
|
||||||
$e = new \Exception();
|
$e = new \Exception();
|
||||||
$trace = $e->getTrace();
|
$trace = $e->getTrace();
|
||||||
}
|
}
|
||||||
|
}
|
||||||
|
|
||||||
$messages = [];
|
$messages = [];
|
||||||
$j = 0;
|
$j = 0;
|
||||||
for($i = (int) $start; isset($trace[$i]); ++$i, ++$j){
|
for($i = (int) $start; isset($trace[$i]); ++$i, ++$j){
|
||||||
@ -203,7 +206,7 @@ namespace pocketmine {
|
|||||||
return rtrim(str_replace(["\\", ".php", "phar://", rtrim(str_replace(["\\", "phar://"], ["/", ""], \pocketmine\PATH), "/"), rtrim(str_replace(["\\", "phar://"], ["/", ""], \pocketmine\PLUGIN_PATH), "/")], ["/", "", "", "", ""], $path), "/");
|
return rtrim(str_replace(["\\", ".php", "phar://", rtrim(str_replace(["\\", "phar://"], ["/", ""], \pocketmine\PATH), "/"), rtrim(str_replace(["\\", "phar://"], ["/", ""], \pocketmine\PLUGIN_PATH), "/")], ["/", "", "", "", ""], $path), "/");
|
||||||
}
|
}
|
||||||
|
|
||||||
function error_handler($errno, $errstr, $errfile, $errline){
|
function error_handler($errno, $errstr, $errfile, $errline, $trace = null){
|
||||||
global $lastError;
|
global $lastError;
|
||||||
if(error_reporting() === 0){ //@ error-control
|
if(error_reporting() === 0){ //@ error-control
|
||||||
return false;
|
return false;
|
||||||
@ -234,7 +237,8 @@ namespace pocketmine {
|
|||||||
$oldFile = $errfile;
|
$oldFile = $errfile;
|
||||||
$errfile = cleanPath($errfile);
|
$errfile = cleanPath($errfile);
|
||||||
$logger->log($type, "An $errno error happened: \"$errstr\" in \"$errfile\" at line $errline");
|
$logger->log($type, "An $errno error happened: \"$errstr\" in \"$errfile\" at line $errline");
|
||||||
foreach(($trace = getTrace(3)) as $i => $line){
|
|
||||||
|
foreach(($trace = getTrace($trace === null ? 3 : 0, $trace)) as $i => $line){
|
||||||
$logger->debug($line);
|
$logger->debug($line);
|
||||||
}
|
}
|
||||||
$lastError = [
|
$lastError = [
|
||||||
|
@ -1053,7 +1053,7 @@ class Server{
|
|||||||
}
|
}
|
||||||
|
|
||||||
if(($provider = LevelProviderManager::getProviderByName($this->getProperty("level-settings.default-format", "mcregion"))) === null){
|
if(($provider = LevelProviderManager::getProviderByName($this->getProperty("level-settings.default-format", "mcregion"))) === null){
|
||||||
$provider = "pocketmine\\level\\format\\mcregion\\McRegion";
|
$provider = LevelProviderManager::getProviderByName("mcregion");
|
||||||
}
|
}
|
||||||
|
|
||||||
$path = $this->getDataPath() . "worlds/" . $name . "/";
|
$path = $this->getDataPath() . "worlds/" . $name . "/";
|
||||||
@ -1450,7 +1450,7 @@ class Server{
|
|||||||
$this->setConfigInt("difficulty", 3);
|
$this->setConfigInt("difficulty", 3);
|
||||||
}
|
}
|
||||||
|
|
||||||
define("pocketmine\\DEBUG", $this->getProperty("debug.level", 1));
|
define("pocketmine\\DEBUG", (int) $this->getProperty("debug.level", 1));
|
||||||
if($this->logger instanceof MainLogger){
|
if($this->logger instanceof MainLogger){
|
||||||
$this->logger->setLogDebug(\pocketmine\DEBUG > 1);
|
$this->logger->setLogDebug(\pocketmine\DEBUG > 1);
|
||||||
}
|
}
|
||||||
@ -1490,8 +1490,9 @@ class Server{
|
|||||||
$this->pluginManager->setUseTimings($this->getProperty("settings.enable-profiling", false));
|
$this->pluginManager->setUseTimings($this->getProperty("settings.enable-profiling", false));
|
||||||
$this->pluginManager->registerInterface("pocketmine\\plugin\\PharPluginLoader");
|
$this->pluginManager->registerInterface("pocketmine\\plugin\\PharPluginLoader");
|
||||||
|
|
||||||
register_shutdown_function(array($this, "crashDump"));
|
set_exception_handler([$this, "exceptionHandler"]);
|
||||||
register_shutdown_function(array($this, "forceShutdown"));
|
register_shutdown_function([$this, "crashDump"]);
|
||||||
|
register_shutdown_function([$this, "forceShutdown"]);
|
||||||
|
|
||||||
$this->pluginManager->loadPlugins($this->pluginPath);
|
$this->pluginManager->loadPlugins($this->pluginPath);
|
||||||
|
|
||||||
@ -1805,6 +1806,20 @@ class Server{
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public function exceptionHandler(\Exception $e){
|
||||||
|
if($e === null){
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
error_handler(E_ERROR, $e->getMessage(), $e->getFile(), $e->getLine(), $e->getTrace());
|
||||||
|
global $lastExceptionError, $lastError;
|
||||||
|
$lastExceptionError = $lastError;
|
||||||
|
$this->crashDump();
|
||||||
|
$this->forceShutdown();
|
||||||
|
kill(getmypid());
|
||||||
|
exit(1);
|
||||||
|
}
|
||||||
|
|
||||||
public function crashDump(){
|
public function crashDump(){
|
||||||
if($this->isRunning === false){
|
if($this->isRunning === false){
|
||||||
return;
|
return;
|
||||||
|
Loading…
x
Reference in New Issue
Block a user