mirror of
https://github.com/pmmp/PocketMine-MP.git
synced 2025-09-06 17:59:48 +00:00
All pocketmine\thread\Thread now log uncaught exceptions and fatal errors by default
This commit is contained in:
@ -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));
|
||||
}
|
||||
});
|
||||
}
|
||||
|
Reference in New Issue
Block a user