Ignore non-fatal error types in crash handlers

ErrorToExceptionHandler currently prevents these from appearing by turning them into exceptions, but this won't always be the case.
For example, in the future we may not want to turn ALL types of E_* errors into exceptions (e.g. E_DEPRECATED).
This commit is contained in:
Dylan K. Taylor 2024-04-02 19:22:40 +01:00
parent dad9a7e6cd
commit 98380e46bf
No known key found for this signature in database
GPG Key ID: 8927471A91CAFD3D
2 changed files with 12 additions and 2 deletions

View File

@ -63,6 +63,12 @@ use function strpos;
use function substr;
use function zend_version;
use function zlib_encode;
use const E_COMPILE_ERROR;
use const E_CORE_ERROR;
use const E_ERROR;
use const E_PARSE;
use const E_RECOVERABLE_ERROR;
use const E_USER_ERROR;
use const FILE_IGNORE_NEW_LINES;
use const JSON_THROW_ON_ERROR;
use const JSON_UNESCAPED_SLASHES;
@ -85,6 +91,9 @@ class CrashDump{
public const PLUGIN_INVOLVEMENT_DIRECT = "direct";
public const PLUGIN_INVOLVEMENT_INDIRECT = "indirect";
public const FATAL_ERROR_MASK =
E_ERROR | E_PARSE | E_CORE_ERROR | E_COMPILE_ERROR | E_USER_ERROR | E_RECOVERABLE_ERROR;
private CrashDumpData $data;
private string $encodedData;
@ -186,7 +195,7 @@ class CrashDump{
$error = $lastExceptionError;
}else{
$error = error_get_last();
if($error === null){
if($error === null || ($error["type"] & self::FATAL_ERROR_MASK) === 0){
throw new \RuntimeException("Crash error information missing - did something use exit()?");
}
$error["trace"] = Utils::printableTrace(Utils::currentTrace(3)); //Skipping CrashDump->baseCrash, CrashDump->construct, Server->crashDump

View File

@ -25,6 +25,7 @@ namespace pocketmine\thread;
use pmmp\thread\Thread as NativeThread;
use pmmp\thread\ThreadSafeArray;
use pocketmine\crash\CrashDump;
use pocketmine\errorhandler\ErrorToExceptionHandler;
use pocketmine\Server;
use function error_get_last;
@ -150,7 +151,7 @@ trait CommonThreadPartsTrait{
$this->synchronized(function() : void{
if($this->isTerminated() && $this->crashInfo === null){
$last = error_get_last();
if($last !== null){
if($last !== null && ($last["type"] & CrashDump::FATAL_ERROR_MASK) !== 0){
//fatal error
$crashInfo = ThreadCrashInfo::fromLastErrorInfo($last, $this->getThreadName());
}else{