-
Notifications
You must be signed in to change notification settings - Fork 63
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
fix(agent): Fix error reporting when EH_THROW is enabled
/* * For a the following error codes: * E_WARNING || E_CORE_WARNING || E_COMPILE_WARNING || E_USER_WARNING * PHP triggers an exception if EH_THROW is toggled on and then immediately * returns after throwing the exception. See for more info: * https://github.com/php/php-src/blob/master/main/main.c In that case, we * should not handle it, but we should exist and let the exception handler * deal with it; otherwise, we could record an error even if an exception is * caught. */
- Loading branch information
Showing
3 changed files
with
213 additions
and
2 deletions.
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
76 changes: 76 additions & 0 deletions
76
tests/integration/errors/test_EH_THROW_errors_caught_exception.php
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,76 @@ | ||
<?php | ||
/* | ||
* Copyright 2020 New Relic Corporation. All rights reserved. | ||
* SPDX-License-Identifier: Apache-2.0 | ||
*/ | ||
|
||
/*DESCRIPTION | ||
For a certain number of error codes, PHP triggers an exception if EH_THROW is toggled on. | ||
Verify we don't record the error if the exception is thrown and caught. | ||
There should be no traced errors, error events, or errors attached to span events. | ||
*/ | ||
|
||
/*SKIPIF | ||
<?php | ||
if (version_compare(PHP_VERSION, "7.0", "<")) { | ||
die("skip: PHP < 7.0 not supported\n"); | ||
} | ||
*/ | ||
|
||
/*INI | ||
display_errors=1 | ||
log_errors=0 | ||
error_reporting=E_ALL | ||
*/ | ||
|
||
/*EXPECT_SPAN_EVENTS | ||
[ | ||
"?? agent run id", | ||
{ | ||
"reservoir_size": 10000, | ||
"events_seen": 1 | ||
}, | ||
[ | ||
[ | ||
{ | ||
"traceId": "??", | ||
"duration": "??", | ||
"transactionId": "??", | ||
"name": "OtherTransaction\/php__FILE__", | ||
"guid": "??", | ||
"type": "Span", | ||
"category": "generic", | ||
"priority": "??", | ||
"sampled": true, | ||
"nr.entryPoint": true, | ||
"timestamp": "??", | ||
"transaction.name": "OtherTransaction\/php__FILE__" | ||
}, | ||
{}, | ||
{} | ||
] | ||
] | ||
] | ||
*/ | ||
|
||
|
||
/*EXPECT_REGEX | ||
Exception caught* | ||
*/ | ||
|
||
/*EXPECT_TRACED_ERRORS | ||
null | ||
*/ | ||
|
||
/*EXPECT_ERROR_EVENTS | ||
null | ||
*/ | ||
|
||
$base_directory = __DIR__ . '/nonexist';; | ||
|
||
try { | ||
$n = new RecursiveDirectoryIterator( $base_directory ) ; | ||
} | ||
catch (\Exception $e) { | ||
echo ("Exception caught: " . $e->getMessage()); | ||
} |
119 changes: 119 additions & 0 deletions
119
tests/integration/errors/test_EH_THROW_errors_uncaught_exception.php
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,119 @@ | ||
<?php | ||
/* | ||
* Copyright 2020 New Relic Corporation. All rights reserved. | ||
* SPDX-License-Identifier: Apache-2.0 | ||
*/ | ||
|
||
/*DESCRIPTION | ||
For a certain number of error codes, PHP triggers an exception if EH_THROW is toggled on. | ||
Verify we don't record the error if the exception is thrown and NOT caught. | ||
There should be traced errors, error events, and an error attached to span events. | ||
*/ | ||
|
||
/*SKIPIF | ||
<?php | ||
if (version_compare(PHP_VERSION, "7.0", "<")) { | ||
die("skip: PHP < 7.0 not supported\n"); | ||
} | ||
*/ | ||
|
||
/*INI | ||
display_errors=1 | ||
log_errors=0 | ||
error_reporting=E_ALL | ||
*/ | ||
|
||
/*EXPECT_SPAN_EVENTS | ||
[ | ||
"?? agent run id", | ||
{ | ||
"reservoir_size": 10000, | ||
"events_seen": 1 | ||
}, | ||
[ | ||
[ | ||
{ | ||
"traceId": "??", | ||
"duration": "??", | ||
"transactionId": "??", | ||
"name": "OtherTransaction\/php__FILE__", | ||
"guid": "??", | ||
"type": "Span", | ||
"category": "generic", | ||
"priority": "??", | ||
"sampled": true, | ||
"nr.entryPoint": true, | ||
"timestamp": "??", | ||
"transaction.name": "OtherTransaction\/php__FILE__" | ||
}, | ||
{}, | ||
{ | ||
"error.message": "?? Uncaught exception ??", | ||
"error.class": "UnexpectedValueException" | ||
} | ||
] | ||
] | ||
] | ||
*/ | ||
|
||
|
||
|
||
/*EXPECT_REGEX | ||
Fatal error* | ||
*/ | ||
|
||
/*EXPECT_TRACED_ERRORS | ||
[ | ||
"?? agent run id", | ||
[ | ||
[ | ||
"?? when", | ||
"OtherTransaction/php__FILE__", | ||
"?? Uncaught exception ??", | ||
"UnexpectedValueException", | ||
{ | ||
"stack_trace": "??", | ||
"agentAttributes": "??", | ||
"intrinsics": "??" | ||
}, | ||
"?? transaction ID" | ||
] | ||
] | ||
] | ||
*/ | ||
|
||
/*EXPECT_ERROR_EVENTS | ||
[ | ||
"?? agent run id", | ||
{ | ||
"reservoir_size": "??", | ||
"events_seen": 1 | ||
}, | ||
[ | ||
[ | ||
{ | ||
"type": "TransactionError", | ||
"timestamp": "??", | ||
"error.class": "UnexpectedValueException", | ||
"error.message": "?? Uncaught exception ??", | ||
"transactionName": "OtherTransaction\/php__FILE__", | ||
"duration": "??", | ||
"nr.transactionGuid": "??", | ||
"guid": "??", | ||
"sampled": true, | ||
"priority": "??", | ||
"traceId": "??", | ||
"spanId": "??" | ||
}, | ||
{}, | ||
{} | ||
] | ||
] | ||
] | ||
*/ | ||
|
||
$base_directory = __DIR__ . '/nonexist';; | ||
|
||
$n = new RecursiveDirectoryIterator( $base_directory ); | ||
|
||
echo("Should not get here"); |