2022-05-16 14:22:21 +03:00
|
|
|
<?php
|
|
|
|
|
|
|
|
function _gamectl_error_handler($errno, $errstr, $errfile, $errline)
|
|
|
|
{
|
|
|
|
if($errno == E_STRICT)
|
|
|
|
return;
|
|
|
|
|
2024-05-02 12:12:46 +03:00
|
|
|
$PHP_8_SUPPRESSED = E_ERROR | E_CORE_ERROR | E_COMPILE_ERROR | E_USER_ERROR | E_RECOVERABLE_ERROR | E_PARSE;
|
|
|
|
$err_rep = error_reporting();
|
|
|
|
// check if error was suppressed by @
|
|
|
|
if($err_rep === 0 || $err_rep === $PHP_8_SUPPRESSED)
|
2022-05-16 14:22:21 +03:00
|
|
|
return;
|
|
|
|
|
|
|
|
$err = "Error happened: $errno, $errstr, $errfile, $errline\n";
|
|
|
|
throw new Exception($err);
|
|
|
|
}
|
|
|
|
|
|
|
|
function _gamectl_exception_handler($e)
|
|
|
|
{
|
2023-11-12 15:33:54 +03:00
|
|
|
$lines = preg_split("/\r\n|\n|\r/", $e->getMessage());
|
|
|
|
$digest = '';
|
|
|
|
//let's filter out too stack traces which are printed anyway
|
|
|
|
foreach($lines as $idx => $line)
|
|
|
|
{
|
|
|
|
if($idx > 0 && preg_match('~^#\d+\s+~', $line))
|
|
|
|
break;
|
|
|
|
$digest .= $line . "\n";
|
|
|
|
}
|
|
|
|
$digest = trim($digest);
|
|
|
|
|
|
|
|
$msg = $e . "\n=== ERROR DIGEST ===\n" . $digest . "\n";
|
2022-05-16 14:22:21 +03:00
|
|
|
$stderr = fopen('php://stderr', 'a');
|
|
|
|
fwrite($stderr, $msg);
|
|
|
|
fclose($stderr);
|
|
|
|
exit(1);
|
|
|
|
}
|
|
|
|
|
|
|
|
set_error_handler("_gamectl_error_handler");
|
|
|
|
set_exception_handler("_gamectl_exception_handler");
|
|
|
|
|