Skip to content

Commit

Permalink
Update Handler.php
Browse files Browse the repository at this point in the history
ignore errors that are not set via error_reporting() in shutdown handler
  • Loading branch information
christopheg authored May 26, 2021
1 parent bd34cf5 commit d9d8c9e
Showing 1 changed file with 24 additions and 1 deletion.
25 changes: 24 additions & 1 deletion lib/Skeleton/Error/Handler.php
Original file line number Diff line number Diff line change
Expand Up @@ -37,6 +37,13 @@ class Handler {
*/
private $is_registered = false;

/**
* Error reporting
*
* @var int $error_reporting
*/
private $error_reporting = false;

/**
* Enable the error handler, assuming defaults
*/
Expand All @@ -55,6 +62,9 @@ public function register() {
return;
}

$this->error_reporting = error_reporting();
error_reporting(0);

// Automatically use sentry/sentry if detected
if ($this->detected_sentry_raven() === true && Config::$sentry_dsn !== null) {
$this->add_handler(new Handler\SentryRaven());
Expand Down Expand Up @@ -90,6 +100,7 @@ public function register() {
register_shutdown_function([$this, 'handle_shutdown']);
set_error_handler([$this, 'handle_error']);
set_exception_handler([$this, 'handle_exception']);


$this->is_registered = true;
}
Expand Down Expand Up @@ -175,7 +186,7 @@ public function handle_exception($exception) {
* @return bool
*/
public function handle_error($level, $message, $file = null, $line = null) {
if ($level & error_reporting()) {
if ($level & $this->error_reporting) {
if ($this->is_silenced($file)) {
return true;
}
Expand All @@ -198,6 +209,18 @@ public function handle_shutdown() {
return;
}
$error = error_get_last();
if ($error === null) {
return true;
}

/**
* We cannot handle errors of any type.
* The following errors shall be handled
*/
if (!($error['type'] & $this->error_reporting)) {
return;
}

if ($error !== null) {
$this->handle_exception(new \ErrorException($error['message'], 0, $error['type'], $error['file'], $error['line']));
}
Expand Down

0 comments on commit d9d8c9e

Please sign in to comment.