From 00b4cadfcf338f34a8e48fa27c75131763f36d14 Mon Sep 17 00:00:00 2001 From: kagg-design Date: Sat, 21 Dec 2024 15:45:17 +0200 Subject: [PATCH 1/5] Ignore PhpStorm folder. --- .gitignore | 1 + 1 file changed, 1 insertion(+) diff --git a/.gitignore b/.gitignore index 13aa3d70a..580845e43 100644 --- a/.gitignore +++ b/.gitignore @@ -1,3 +1,4 @@ +/.idea /assets/*.css /assets/*.map /composer.lock From 8ba2a05abef00da22976957af053ab68492931b1 Mon Sep 17 00:00:00 2001 From: kagg-design Date: Sat, 21 Dec 2024 20:12:24 +0200 Subject: [PATCH 2/5] Support error handlers chain. --- collectors/php_errors.php | 30 +++++++++++++++++++++++++++--- 1 file changed, 27 insertions(+), 3 deletions(-) diff --git a/collectors/php_errors.php b/collectors/php_errors.php index 80631f049..070fcaab8 100644 --- a/collectors/php_errors.php +++ b/collectors/php_errors.php @@ -216,11 +216,13 @@ public function error_handler( $errno, $message, $file = null, $line = null, $co } if ( null === $type ) { - return false; + // phpcs:ignore PHPCompatibility.FunctionUse.ArgumentFunctionsReportCurrentValue.NeedsInspection + return $this->fallback_error_handler( func_get_args() ); } if ( ! class_exists( 'QM_Backtrace' ) ) { - return false; + // phpcs:ignore PHPCompatibility.FunctionUse.ArgumentFunctionsReportCurrentValue.NeedsInspection + return $this->fallback_error_handler( func_get_args() ); } $error_group = 'errors'; @@ -245,7 +247,14 @@ public function error_handler( $errno, $message, $file = null, $line = null, $co // Intentionally skip reporting these core warnings. They're a distraction when developing offline. // The failed HTTP request will still appear in QM's output so it's not a big problem hiding these warnings. if ( false !== strpos( $message, self::$unexpected_error ) ) { - return false; + // phpcs:ignore PHPCompatibility.FunctionUse.ArgumentFunctionsReportCurrentValue.NeedsInspection + return $this->fallback_error_handler( func_get_args() ); + } + + // If the fallback error handler returns true, the error was suppressed. + // phpcs:ignore PHPCompatibility.FunctionUse.ArgumentFunctionsReportCurrentValue.NeedsInspection + if ( $this->fallback_error_handler( func_get_args() ) ) { + return true; } $trace = new QM_Backtrace(); @@ -289,6 +298,21 @@ public function error_handler( $errno, $message, $file = null, $line = null, $co } + /** + * Fallback error handler. + * + * @param array $args Arguments. + * + * @return bool + * @noinspection PhpTernaryExpressionCanBeReplacedWithConditionInspection + */ + private function fallback_error_handler( array $args ): bool { + return null === $this->previous_error_handler ? + // Use standard error handler. + false : + (bool) call_user_func_array( $this->previous_error_handler, $args ); + } + /** * @param string $error * @param mixed[] $e From 1b4a5a3c8d3fabc30787b967c409232bc61f4515 Mon Sep 17 00:00:00 2001 From: kagg-design Date: Sat, 21 Dec 2024 20:30:04 +0200 Subject: [PATCH 3/5] Fix stan. --- collectors/php_errors.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/collectors/php_errors.php b/collectors/php_errors.php index 070fcaab8..e09728652 100644 --- a/collectors/php_errors.php +++ b/collectors/php_errors.php @@ -301,7 +301,7 @@ public function error_handler( $errno, $message, $file = null, $line = null, $co /** * Fallback error handler. * - * @param array $args Arguments. + * @param array $args Arguments. * * @return bool * @noinspection PhpTernaryExpressionCanBeReplacedWithConditionInspection From 43aa02d400b400285be6b7fe5d37f9586bf59120 Mon Sep 17 00:00:00 2001 From: kagg-design Date: Sat, 21 Dec 2024 20:58:49 +0200 Subject: [PATCH 4/5] Fix stan. --- collectors/php_errors.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/collectors/php_errors.php b/collectors/php_errors.php index e09728652..5b36f9d51 100644 --- a/collectors/php_errors.php +++ b/collectors/php_errors.php @@ -301,7 +301,7 @@ public function error_handler( $errno, $message, $file = null, $line = null, $co /** * Fallback error handler. * - * @param array $args Arguments. + * @param mixed[] $args Arguments. * * @return bool * @noinspection PhpTernaryExpressionCanBeReplacedWithConditionInspection From ffed251422ad65e4412b62c4bb580cf25994c5a2 Mon Sep 17 00:00:00 2001 From: kagg-design Date: Sun, 22 Dec 2024 13:53:04 +0200 Subject: [PATCH 5/5] Set error handler with E_ALL and ignore fatal errors in the handler to support chaining. --- collectors/php_errors.php | 9 ++++++++- 1 file changed, 8 insertions(+), 1 deletion(-) diff --git a/collectors/php_errors.php b/collectors/php_errors.php index 5b36f9d51..81ebc7fdc 100644 --- a/collectors/php_errors.php +++ b/collectors/php_errors.php @@ -83,7 +83,8 @@ public function set_up() { $prior_error = error_get_last(); // Non-fatal error handler: - $this->previous_error_handler = set_error_handler( array( $this, 'error_handler' ), ( E_ALL ^ QM_ERROR_FATALS ) ); + // To support error handler chaining, we need to set our error handler with E_ALL error_levels. + $this->previous_error_handler = set_error_handler( array( $this, 'error_handler' ) ); // Fatal error and uncaught exception handler: $this->previous_exception_handler = set_exception_handler( array( $this, 'exception_handler' ) ); @@ -176,6 +177,12 @@ public function exception_handler( $e ) { * @return bool */ public function error_handler( $errno, $message, $file = null, $line = null, $context = null, $do_trace = true ) { + if ( $errno & QM_ERROR_FATALS ) { + // Do not proceed with fatal errors. + // phpcs:ignore PHPCompatibility.FunctionUse.ArgumentFunctionsReportCurrentValue.NeedsInspection + return $this->fallback_error_handler( func_get_args() ); + } + $type = null; /**