-
Notifications
You must be signed in to change notification settings - Fork 7.8k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
RFC: Error Backtraces v2 #17056
Open
ericnorris
wants to merge
10
commits into
php:master
Choose a base branch
from
ericnorris:feat-error-backtrace-v2
base: master
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
+157
−6
Open
RFC: Error Backtraces v2 #17056
Changes from all commits
Commits
Show all changes
10 commits
Select commit
Hold shift + click to select a range
3b9bd2f
rfc: error_backtraces_v2
ericnorris aa9c4f4
address second round of PR comments
ericnorris 47148c1
use `eval` instead of `new_oom.inc`
ericnorris a44ac31
fix tests that invoke PHP and thus don't inherit run-tests.php INI se…
ericnorris e843e06
clear backtrace when throwing an exception
ericnorris 2cd6c3f
address third round of PR comments
ericnorris aaa2443
move initialization of error_backtrace to handle NTS
ericnorris 5fd14ee
move `error_get_last` w/ fatal to separate test
ericnorris b1db022
rename `error_backtrace` global to `fatal_error_backtrace`
ericnorris 9f29e80
rename `fatal_error_backtrace` -> `last_fatal_error_backtrace`
ericnorris File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,14 @@ | ||
--TEST-- | ||
Fatal error backtrace | ||
--INI-- | ||
fatal_error_backtraces=On | ||
--FILE-- | ||
<?php | ||
|
||
eval("class Foo {}; class Foo {}"); | ||
?> | ||
--EXPECTF-- | ||
Fatal error: Cannot redeclare class Foo (%s) in %s : eval()'d code on line %d | ||
Stack trace: | ||
#0 %sfatal_error_backtraces_001.php(%d): eval() | ||
#1 {main} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,19 @@ | ||
--TEST-- | ||
Fatal error backtrace w/ sensitive parameters | ||
--INI-- | ||
fatal_error_backtraces=On | ||
--FILE-- | ||
<?php | ||
|
||
function trigger_fatal(#[\SensitiveParameter] $unused) { | ||
eval("class Foo {}; class Foo {}"); | ||
} | ||
|
||
trigger_fatal("bar"); | ||
?> | ||
--EXPECTF-- | ||
Fatal error: Cannot redeclare class Foo (%s) in %s : eval()'d code on line %d | ||
Stack trace: | ||
#0 %sfatal_error_backtraces_002.php(%d): eval() | ||
#1 %sfatal_error_backtraces_002.php(%d): trigger_fatal(Object(SensitiveParameterValue)) | ||
#2 {main} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,20 @@ | ||
--TEST-- | ||
Fatal error backtrace w/ zend.exception_ignore_args | ||
--INI-- | ||
fatal_error_backtraces=On | ||
zend.exception_ignore_args=On | ||
--FILE-- | ||
<?php | ||
|
||
function trigger_fatal($unused) { | ||
eval("class Foo {}; class Foo {}"); | ||
} | ||
|
||
trigger_fatal("bar"); | ||
?> | ||
--EXPECTF-- | ||
Fatal error: Cannot redeclare class Foo (%s) in %s : eval()'d code on line %d | ||
Stack trace: | ||
#0 %sfatal_error_backtraces_003.php(%d): eval() | ||
#1 %sfatal_error_backtraces_003.php(%d): trigger_fatal() | ||
#2 {main} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
59 changes: 59 additions & 0 deletions
59
ext/standard/tests/general_functions/error_get_last_002.phpt
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,59 @@ | ||
--TEST-- | ||
error_get_last() w/ fatal error | ||
--INI-- | ||
fatal_error_backtraces=On | ||
--FILE-- | ||
<?php | ||
|
||
function trigger_fatal_error_with_stacktrace() { | ||
eval("class Foo {}; class Foo {}"); | ||
} | ||
|
||
register_shutdown_function(function() { | ||
var_dump(error_get_last()); | ||
echo "Done\n"; | ||
}); | ||
|
||
trigger_fatal_error_with_stacktrace(); | ||
?> | ||
--EXPECTF-- | ||
Fatal error: Cannot redeclare class Foo (%s) in %s on line %d | ||
Stack trace: | ||
#0 %serror_get_last_002.php(%d): eval() | ||
#1 %serror_get_last_002.php(%d): trigger_fatal_error_with_stacktrace() | ||
#2 {main} | ||
array(5) { | ||
["type"]=> | ||
int(64) | ||
["message"]=> | ||
string(%d) "Cannot redeclare class Foo %s" | ||
["file"]=> | ||
string(%d) "%serror_get_last_002.php(%d) : eval()'d code" | ||
["line"]=> | ||
int(%d) | ||
["trace"]=> | ||
array(2) { | ||
[0]=> | ||
array(3) { | ||
["file"]=> | ||
string(%d) "%serror_get_last_002.php" | ||
["line"]=> | ||
int(%d) | ||
["function"]=> | ||
string(%d) "eval" | ||
} | ||
[1]=> | ||
array(4) { | ||
["file"]=> | ||
string(%d) "%serror_get_last_002.php" | ||
["line"]=> | ||
int(%d) | ||
["function"]=> | ||
string(%d) "trigger_fatal_error_with_stacktrace" | ||
["args"]=> | ||
array(0) { | ||
} | ||
} | ||
} | ||
} | ||
Done |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This is supposed to be readable in HTML, but I doubt the backtrace will be displayed in a readable manner. Perhaps, this should be wrapped in a
<pre>
tag or smth alike?There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Good catch, I'll look into that.
Semi-related tangent so feel free to disregard: Is it on anyone's radar to refactor this function at all? I saw "Deprecate the
error_prepend_string
anderror_append_string
INI directives" in https://wiki.php.net/rfc/deprecations_php_8_5, which would help make this a little more readable, but I wonder if there's more we could do simplify this logic. I acknowledge that is probably easier said than done, however.There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I doubt refactoring this function is on someone's TODO list. There are indeed some outdated pieces (e.g. the ones you mentioned but also xmlrpc_errors imo). However, the question with refactoring is always how much it's worth spending time on this. This function likely is not on any hot code path and refactoring also brings in a risk of breaking things 🤷
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
would be also nice to break up those huge long lines when you are in it...
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@nielsdos apologies, but what's the best way to wrap a
zend_string
in<pre>
?strpprintf
? Or would it be the worst thing to just change this to%s%s%s
and then pass inZSTR_LEN(backtrace) ? "<pre>Stack trace:\n" : "", ZSTR_VAL(backtrace), ZSTR_LEN(backtrace) ? "</pre>" : ""
? We could also drop adding thepre
at all since we already have some fatal errors with stack traces that do not havepre
: /~https://github.com/search?q=repo%3Aphp%2Fphp-src+%22%3Cb%3EFatal+error%3C%2Fb%3E%22&type=code, e.g.@bukka I received feedback elsewhere to not break up long lines, though maybe here is a good counterpoint. I'd personally like to err on keeping it as-is since I'd like to be able to merge this relatively soon, but if people feel strongly I could break this up. This is kind of what I was getting at with my earlier comment - this function could probably be simplified to make it more readable, besides just the long line length.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
If we wrap it with pre it should be done consistently.
If I were to write the code, I would go for the ZSTR_LEN() ternary trick.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I'm not sure I follow - what I was saying was that we currently do not wrap it with
<pre>
(for errors that already have backtraces before my change), so if we wrap it with<pre>
here we'd be inconsistent with existing errors like:php-src/sapi/cgi/tests/004.phpt
Lines 43 to 46 in 72708f2
Thanks, I was leaning that way but I wanted your opinion. I'm still not convinced we should add the
<pre>
based on the above, but if you think we should I'll go theZSTR_LEN
route.There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
In case you are referring to my remark here: #16937 (comment) - this case of a printf-style function is quite different and splitting it across multiple lines would be reasonable, because it accurately represents the complexity of the statement.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Ok let's not do the
<pre>
conversion.There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@TimWolla I was! and when I said "maybe here is a good counterpoint", I meant that I could see that you might agree with splitting this up. My preference was to not do this myself though, since for consistency I should probably do that for all of them, and I was concerned with making it a topic for bikeshedding.