Skip to content
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

non-existent E_WARNING reported to NewRelic when exception is caught #872

Closed
php4fan opened this issue Apr 7, 2024 · 1 comment · Fixed by #876
Closed

non-existent E_WARNING reported to NewRelic when exception is caught #872

php4fan opened this issue Apr 7, 2024 · 1 comment · Fixed by #876
Labels
bug Something isn't working
Milestone

Comments

@php4fan
Copy link

php4fan commented Apr 7, 2024

Description

I have this code:

$base_directory = __DIR__ . '/lskdns'; 
ini_set('display_errors', true); 
ini_set('error_reporting', E_ALL); 
try { 
       $n = new RecursiveDirectoryIterator( $base_directory ) ; 
} 
catch (\Exception $e) { 
       echo "<hr>Exception caught: " . $e->getMessage() . "<hr>"; 
}

The code inside the try block causes an exception which gets caught. And yet this gets reported to NewRelic as an E_WARNING:

https://onenr.io/0Zw0mMP6ORv

The exception is getting caught, and there is no E_WARNING at all, so there's nothing here to report to NewRelic.

Note that I have ini_set('display_errors', true), so if there was an E_WARNING it would be printed to the output, which is not the case.

Steps to Reproduce

See code above

Expected Behavior

Nothing should be reported to NewRelic

Observed behavior

A non-existent E_WARNING error is reported to NewRelic.

Relevant Logs / Console output

Your Environment

PHP 7.4 on Debian

Additional context

@zsistla
Copy link
Contributor

zsistla commented Apr 11, 2024

Hi @php4fan , thanks for bring this issue to our attention and for providing the reproducible code snippet which really helped when investigating the issue.

#851 is not related to the issue as that is the way the agent has always reported errors with the exception of agent version 10.18.

This was an interesting problem.
In this case, a php E_WARNING error was triggered.  We intercept the error from PHP and record it then pass execution back to PHP.

But this particular case deals with a filehandling which toggles EH_THROW on here: https://github.com/php/php-src/blob/master/ext/fileinfo/fileinfo.c#L176
PHP then handles the error but for a certain number of error codes, PHP triggers an exception if EH_THROW is toggled on: https://github.com/php/php-src/blob/master/main/main.c#L1254C1-L1259C24
and then immediately returns after throwing the exception.

This leads to the case in the issue where the exception that was triggered is caught, but we recorded the error....

It should be addressed in this PR: #876

@lavarou lavarou linked a pull request Apr 25, 2024 that will close this issue
@lavarou lavarou added this to the next-release milestone Apr 25, 2024
@lavarou lavarou closed this as completed May 6, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working
Projects
None yet
Development

Successfully merging a pull request may close this issue.

3 participants