Skip to content

Commit

Permalink
Fixed issue #788: Collect errors eats fatal errors.
Browse files Browse the repository at this point in the history
  • Loading branch information
derickr committed Mar 4, 2012
1 parent e169ff6 commit 0a1ded1
Show file tree
Hide file tree
Showing 4 changed files with 88 additions and 4 deletions.
30 changes: 30 additions & 0 deletions tests/error_collection_1.phpt
@@ -0,0 +1,30 @@
--TEST--
Test for collection errors (1)
--INI--
display_errors=1
xdebug.default_enable=1
html_errors=0
xdebug.collect_params=4
xdebug.overload_var_dump=0
--FILE--
<?php
xdebug_start_error_collection();

trigger_error("An error", E_USER_WARNING);

echo "Errors\n";
var_dump( xdebug_get_collected_errors() );
?>
--EXPECTF--
Errors
array(1) {
[0]=>
string(%d) "
Warning: An error in %serror_collection_1.php on line 4

Call Stack:
%w%f %w%d 1. {main}() %serror_collection_1.php:0
%w%f %w%d 2. trigger_error('An error', 512) %serror_collection_1.php:4

"
}
15 changes: 15 additions & 0 deletions tests/error_collection_2.phpt
@@ -0,0 +1,15 @@
--TEST--
Test for collection errors (2) (fatal error)
--INI--
error_log=NULL
--FILE--
<?php
xdebug_start_error_collection();

trigger_error("An error", E_USER_ERROR);

echo "Errors\n";
var_dump( xdebug_get_collected_errors() );
?>
--EXPECTF--
Fatal error: An error in %serror_collection_2.php on line 4
36 changes: 36 additions & 0 deletions tests/error_collection_3.phpt
@@ -0,0 +1,36 @@
--TEST--
Test for collection errors (3) - HTML errors
--INI--
display_errors=1
xdebug.default_enable=1
html_errors=1
xdebug.overload_var_dump=0
xdebug.file_link_format=xdebug://%f@%l
xdebug.auto_trace=0
xdebug.collect_assignments=1
xdebug.collect_return=1
xdebug.collect_params=4
--FILE--
<?php
xdebug_start_error_collection();

trigger_error("An error", E_USER_WARNING);

echo "Errors\n";
var_dump( xdebug_get_collected_errors() );
?>
--EXPECTF--
Errors
array(1) {
[0]=>
string(%d) "<br />
<font size='1'><table class='xdebug-error' dir='ltr' border='1' cellspacing='0' cellpadding='1'>
<tr><th align='left' bgcolor='#f57900' colspan="5"><span style='background-color: #cc0000; color: #fce94f; font-size: x-large;'>( ! )</span> Warning: An error in <a style='color: black' href='xdebug://%serror_collection_3.php@4'>%serror_collection_3.php</a> on line <i>4</i></th></tr>
<tr><th align='left' bgcolor='#e9b96e' colspan='5'>Call Stack</th></tr>
<tr><th align='center' bgcolor='#eeeeec'>#</th><th align='left' bgcolor='#eeeeec'>Time</th><th align='left' bgcolor='#eeeeec'>Memory</th><th align='left' bgcolor='#eeeeec'>Function</th><th align='left' bgcolor='#eeeeec'>Location</th></tr>
<tr><td bgcolor='#eeeeec' align='center'>1</td><td bgcolor='#eeeeec' align='center'>%f</td><td bgcolor='#eeeeec' align='right'>%d</td><td bgcolor='#eeeeec'>{main}( )</td><td title='%serror_collection_3.php' bgcolor='#eeeeec'><a style='color: black' href='xdebug://%serror_collection_3.php@0'>../error_collection_3.php<b>:</b>0</a></td></tr>
<tr><td bgcolor='#eeeeec' align='center'>2</td><td bgcolor='#eeeeec' align='center'>%f</td><td bgcolor='#eeeeec' align='right'>%d</td><td bgcolor='#eeeeec'><a href='http://www.php.net/trigger_error' target='_new'>trigger_error</a>
( <span>&#39;An error&#39;</span>, <span>512</span> )</td><td title='%serror_collection_3.php' bgcolor='#eeeeec'><a style='color: black' href='xdebug://%serror_collection_3.php@4'>../error_collection_3.php<b>:</b>4</a></td></tr>
</table></font>
"
}
11 changes: 7 additions & 4 deletions xdebug_stack.c
Expand Up @@ -571,11 +571,14 @@ void xdebug_error_cb(int type, const char *error_filename, const uint error_line
free(tmp_buf);
} else {
printable_stack = get_printable_stack(PG(html_errors), error_type_str, buffer, error_filename, error_lineno TSRMLS_CC);
php_output_error(printable_stack TSRMLS_CC);
xdfree(printable_stack);
if (XG(do_collect_errors) && (type != E_ERROR) && (type != E_COMPILE_ERROR) && (type != E_USER_ERROR)) {
xdebug_llist_insert_next(XG(collected_errors), XDEBUG_LLIST_TAIL(XG(collected_errors)), printable_stack);
} else {
php_output_error(printable_stack TSRMLS_CC);
xdfree(printable_stack);
}
}
}
if (XG(do_collect_errors)) {
} else if (XG(do_collect_errors)) {
char *printable_stack;
printable_stack = get_printable_stack(PG(html_errors), error_type_str, buffer, error_filename, error_lineno TSRMLS_CC);
xdebug_llist_insert_next(XG(collected_errors), XDEBUG_LLIST_TAIL(XG(collected_errors)), printable_stack);
Expand Down

0 comments on commit 0a1ded1

Please sign in to comment.