mirror of
https://github.com/pmmp/PocketMine-MP.git
synced 2025-09-06 17:59:48 +00:00
Move some error handling stuff to SPL
This commit is contained in:
@ -60,21 +60,6 @@ use function substr;
|
||||
use function time;
|
||||
use function zend_version;
|
||||
use function zlib_encode;
|
||||
use const E_COMPILE_ERROR;
|
||||
use const E_COMPILE_WARNING;
|
||||
use const E_CORE_ERROR;
|
||||
use const E_CORE_WARNING;
|
||||
use const E_DEPRECATED;
|
||||
use const E_ERROR;
|
||||
use const E_NOTICE;
|
||||
use const E_PARSE;
|
||||
use const E_RECOVERABLE_ERROR;
|
||||
use const E_STRICT;
|
||||
use const E_USER_DEPRECATED;
|
||||
use const E_USER_ERROR;
|
||||
use const E_USER_NOTICE;
|
||||
use const E_USER_WARNING;
|
||||
use const E_WARNING;
|
||||
use const FILE_IGNORE_NEW_LINES;
|
||||
use const JSON_UNESCAPED_SLASHES;
|
||||
use const PHP_EOL;
|
||||
@ -217,26 +202,13 @@ class CrashDump{
|
||||
}else{
|
||||
$error = (array) error_get_last();
|
||||
$error["trace"] = Utils::currentTrace(3); //Skipping CrashDump->baseCrash, CrashDump->construct, Server->crashDump
|
||||
$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"] = Utils::cleanPath($error["file"]);
|
||||
$error["type"] = $errorConversion[$error["type"]] ?? $error["type"];
|
||||
try{
|
||||
$error["type"] = \ErrorUtils::errorTypeToString($error["type"]);
|
||||
}catch(\InvalidArgumentException $e){
|
||||
//pass
|
||||
}
|
||||
if(($pos = strpos($error["message"], "\n")) !== false){
|
||||
$error["message"] = substr($error["message"], 0, $pos);
|
||||
}
|
||||
|
@ -163,7 +163,7 @@ namespace pocketmine {
|
||||
exit(1);
|
||||
}
|
||||
|
||||
set_error_handler([Utils::class, 'errorExceptionHandler']);
|
||||
\ErrorUtils::setErrorExceptionHandler();
|
||||
|
||||
/*
|
||||
* We now use the Composer autoloader, but this autoloader is still for loading plugins.
|
||||
|
@ -24,12 +24,10 @@ declare(strict_types=1);
|
||||
namespace pocketmine\scheduler;
|
||||
|
||||
use pocketmine\utils\MainLogger;
|
||||
use pocketmine\utils\Utils;
|
||||
use pocketmine\Worker;
|
||||
use function error_reporting;
|
||||
use function gc_enable;
|
||||
use function ini_set;
|
||||
use function set_error_handler;
|
||||
|
||||
class AsyncWorker extends Worker{
|
||||
/** @var mixed[] */
|
||||
@ -53,7 +51,7 @@ class AsyncWorker extends Worker{
|
||||
$this->registerClassLoader();
|
||||
|
||||
//set this after the autoloader is registered
|
||||
set_error_handler([Utils::class, 'errorExceptionHandler']);
|
||||
\ErrorUtils::setErrorExceptionHandler();
|
||||
|
||||
\GlobalLogger::set($this->logger);
|
||||
if($this->logger instanceof MainLogger){
|
||||
|
@ -36,19 +36,8 @@ use function sprintf;
|
||||
use function time;
|
||||
use function touch;
|
||||
use function trim;
|
||||
use const E_COMPILE_ERROR;
|
||||
use const E_COMPILE_WARNING;
|
||||
use const E_CORE_ERROR;
|
||||
use const E_CORE_WARNING;
|
||||
use const E_DEPRECATED;
|
||||
use const E_ERROR;
|
||||
use const E_NOTICE;
|
||||
use const E_PARSE;
|
||||
use const E_RECOVERABLE_ERROR;
|
||||
use const E_STRICT;
|
||||
use const E_USER_DEPRECATED;
|
||||
use const E_USER_ERROR;
|
||||
use const E_USER_NOTICE;
|
||||
use const E_USER_WARNING;
|
||||
use const E_WARNING;
|
||||
use const PHP_EOL;
|
||||
@ -209,30 +198,16 @@ class MainLogger extends \AttachableThreadedLogger{
|
||||
$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 = $errorConversion[$errno] ?? $errno;
|
||||
try{
|
||||
$errno = \ErrorUtils::errorTypeToString($errno);
|
||||
}catch(\InvalidArgumentException $e){
|
||||
//pass
|
||||
}
|
||||
$errstr = preg_replace('/\s+/', ' ', trim($errstr));
|
||||
$errfile = Utils::cleanPath($errfile);
|
||||
|
||||
|
@ -39,7 +39,6 @@ use function chunk_split;
|
||||
use function count;
|
||||
use function debug_zval_dump;
|
||||
use function dechex;
|
||||
use function error_reporting;
|
||||
use function exec;
|
||||
use function explode;
|
||||
use function fclose;
|
||||
@ -628,23 +627,6 @@ class Utils{
|
||||
return array_combine($matches[1], $matches[2]);
|
||||
}
|
||||
|
||||
/**
|
||||
* @param int $severity
|
||||
* @param string $message
|
||||
* @param string $file
|
||||
* @param int $line
|
||||
*
|
||||
* @return bool
|
||||
* @throws \ErrorException
|
||||
*/
|
||||
public static function errorExceptionHandler(int $severity, string $message, string $file, int $line) : bool{
|
||||
if(error_reporting() & $severity){
|
||||
throw new \ErrorException($message, 0, $severity, $file, $line);
|
||||
}
|
||||
|
||||
return true; //stfu operator
|
||||
}
|
||||
|
||||
public static function testValidInstance(string $className, string $baseName) : void{
|
||||
try{
|
||||
$base = new \ReflectionClass($baseName);
|
||||
|
Reference in New Issue
Block a user