mirror of
https://github.com/pmmp/PocketMine-MP.git
synced 2025-04-20 16:00:20 +00:00
All pocketmine\thread\Thread now log uncaught exceptions and fatal errors by default
This commit is contained in:
parent
2e58387a43
commit
2559d1719f
@ -85,6 +85,7 @@ class RakLibServer extends Thread{
|
||||
gc_enable();
|
||||
ini_set("display_errors", '1');
|
||||
ini_set("display_startup_errors", '1');
|
||||
\GlobalLogger::set($this->logger);
|
||||
|
||||
$socket = new ServerSocket($this->address->deserialize());
|
||||
$manager = new Server(
|
||||
@ -107,11 +108,6 @@ class RakLibServer extends Thread{
|
||||
$manager->waitShutdown();
|
||||
}
|
||||
|
||||
protected function onUncaughtException(\Throwable $e) : void{
|
||||
parent::onUncaughtException($e);
|
||||
$this->logger->logException($e);
|
||||
}
|
||||
|
||||
public function getThreadName() : string{
|
||||
return "RakLib";
|
||||
}
|
||||
|
@ -69,11 +69,6 @@ class AsyncWorker extends Worker{
|
||||
$this->saveToThreadStore(self::TLS_KEY_NOTIFIER, $this->sleeperEntry->createNotifier());
|
||||
}
|
||||
|
||||
protected function onUncaughtException(\Throwable $e) : void{
|
||||
parent::onUncaughtException($e);
|
||||
$this->logger->logException($e);
|
||||
}
|
||||
|
||||
public function getLogger() : ThreadSafeLogger{
|
||||
return $this->logger;
|
||||
}
|
||||
|
@ -115,6 +115,7 @@ trait CommonThreadPartsTrait{
|
||||
protected function onUncaughtException(\Throwable $e) : void{
|
||||
$this->synchronized(function() use ($e) : void{
|
||||
$this->crashInfo = ThreadCrashInfo::fromThrowable($e, $this->getThreadName());
|
||||
\GlobalLogger::get()->logException($e);
|
||||
});
|
||||
}
|
||||
|
||||
@ -128,11 +129,22 @@ trait CommonThreadPartsTrait{
|
||||
$last = error_get_last();
|
||||
if($last !== null){
|
||||
//fatal error
|
||||
$this->crashInfo = ThreadCrashInfo::fromLastErrorInfo($last, $this->getThreadName());
|
||||
$crashInfo = ThreadCrashInfo::fromLastErrorInfo($last, $this->getThreadName());
|
||||
}else{
|
||||
//probably misused exit()
|
||||
$this->crashInfo = ThreadCrashInfo::fromThrowable(new \RuntimeException("Thread crashed without an error - perhaps exit() was called?"), $this->getThreadName());
|
||||
$crashInfo = ThreadCrashInfo::fromThrowable(new \RuntimeException("Thread crashed without an error - perhaps exit() was called?"), $this->getThreadName());
|
||||
}
|
||||
$this->crashInfo = $crashInfo;
|
||||
|
||||
$lines = [];
|
||||
//mimic exception printed format
|
||||
$lines[] = "Fatal error: " . $crashInfo->makePrettyMessage();
|
||||
$lines[] = "--- Stack trace ---";
|
||||
foreach($crashInfo->getTrace() as $frame){
|
||||
$lines[] = " " . $frame->getPrintableFrame();
|
||||
}
|
||||
$lines[] = "--- End of fatal error information ---";
|
||||
\GlobalLogger::get()->critical(implode("\n", $lines));
|
||||
}
|
||||
});
|
||||
}
|
||||
|
Loading…
x
Reference in New Issue
Block a user