[php-src] PR #17056: Feat error backtrace v2

From: Date: Thu, 05 Dec 2024 18:01:01 +0000
Subject: [php-src] PR #17056: Feat error backtrace v2
Groups: php.git-pulls 
Request: Send a blank email to git-pulls+get-29896@lists.php.net to get a copy of this message
Pull Request: https://github.com/php/php-src/pull/17056 Author: ericnorris This pull request seeks to continue the work from #5642, but using an implementation more in line with what nikic suggested in https://externals.io/message/110302#113264: > To put my feedback into more actionable form: Rather than adding an ini setting that enables error backtraces for all diagnostics, I'd make it a mask of error types for which a backtrace should be captured, and default it to fatal errors only. So error_reporting=E_ALL, error_backtrace=E_ERROR|E_CORE_ERROR|E_COMPILE_ERROR|E_USER_ERROR|E_RECOVERABLE_ERROR|E_PARSE. It might be handy to expose the internal E_FATAL_ERRORS constant we have for that. > > I think this should give a very sensible default behavior, and people who want to capture backtraces for all errors still have an option to do so. > > Finally, I'm wondering if the backtrace in error_get_last() shouldn't be in array form, rather than string form. The RFC will be at https://wiki.php.net/rfc/error_backtraces_v2. I've created a new INI setting, error_backtrace_recording, which users can set to an error mask to enable backtraces for those errors. It defaults to E_FATAL_ERRORS, which I've also exposed as a userland constant. Considering the default, any fatal error will now have a backtrace associated with it. For example, a script timeout will now look like: ``` Fatal error: Maximum execution time of 1 second exceeded in example.php on line 23 Stack trace: #0 example.php(23): usleep(10000) #1 example.php(24): recurse() #2 example.php(24): recurse() ... ``` This would have been useful to us very recently: we had an issue in production that presented as "Maximum execution time of X second exceeded" errors, and it was difficult for us to identity the underlying culprit. We eventually identified it as an infinite loop, which would have been incredibly obvious in a trace if it was available. The implementation respects the zend.exception_ignore_args INI setting and the SensitiveParameter attributes, so users can ensure that sensitive arguments do not end up in the backtrace. I have some open questions about this implementation: - Why is zend_startup responsible for setting EG(error_reporting), and not executor_globals_ctor? I've done the same for EG(error_backtrace_recording) purely for consistency. - Is there any appetite for modifying the signature of zend_error_cb? If so, I could pass the backtrace as a nullable argument instead of setting an executor global. I've updated all tests that are now failing due to the stack trace in the second commit, to keep the diff reviewable.

« previous php.git-pulls (#29896) next »