-
Notifications
You must be signed in to change notification settings - Fork 78
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
Reporting unhandled exceptions breaks error page handling #475
Comments
I believe you can call We should improve the documentation here at a minimum. But it feels like that should be the default behaviour. cc @kattrali @Cawllec |
Yes, you can call |
I have tried that, however, https://github.com/bugsnag/bugsnag-php/blob/master/src/Handler.php#L71 overrides shutdown handler anyway. While error and exception handlers preserve original handler, shutdown is overridden. |
Furthermore, bugsnag somehow messes up response code in case of fatal error: This returns status code 500:
This returns status code 200:
|
I'm not in the office the rest of this week, but will get to this as soon as possible once I'm back. |
Any updates @Cawllec? |
Hey @thedotedge, I'm back. So, according to the docs, I'll investigate the incorrect exit code, and see if I can work out what's going on there. |
I've checked out the exit status issue, and it's actually a PHP quirk - when an exception handler is registered PHP will exit with 0 as its exit status. You can override this behaviour by adding your own exception handler that sets the exit code with |
Ping @Cawllec |
Hi, sorry @thedotedge, I meant that you get a 200 status code with an exception handler when running in the browser, and a 0 when running in the console. You should be able to change the response code using the |
Thanks @Cawllec, given that this script is run by php-fpm in the browser, where does one set
|
I'm unsure of how the behaviour would change between vanilla PHP and PHP-FPM, but you if you want to have a callback run after the Bugsnag exception (or error) handler you need to register it before you register the Bugsnag handlers, and you'd need to register them using the <?php
// some code that emits E_NOTICE
// ...
register_shutdown_function(function () use ($bugsnag) {
if ($error = error_get_last()) {
if (in_array($error['type'], [E_ERROR, E_PARSE, E_COMPILE_ERROR, E_CORE_ERROR, E_USER_ERROR])) {
http_response_code(500);
exit();
}
}
});
# When the bugsnag exception handler is added with `registerWithPrevious` it will keep this callable and execute it after notifying.
set_exception_handler(function($exception) {
# Set http_response_code to 500, or any other response tasks post exception-handling
http_response_code(500);
});
$bugsnag = Bugsnag\Client::make($GLOBALS['config']['bugsnag']['api_key']);
# Note - This was Bugsnag\Handler::register, now it's Bugsnag\Handler::registerWithPrevious
Bugsnag\Handler::registerWithPrevious($bugsnag);
throw new \RuntimeException('Triggered error 500'); Try this out and let me know if the behaviour is as expected. |
Thanks @Cawllec, the code above does not seem to work, since |
Sorry it's taken me a while to reply, I've been on leave.
By registering your own exception handler using |
@Cawllec has same error, tryied to use |
Hi! Have you been able to use the steps to reproduce to confirm the issue? |
Hi, like I say, Bugsnag is not changing default PHP behaviour. This is an effect of using the PHP |
This should now be fixed in v3.23.1 |
Expected behavior
When uncaught exception is thrown, bugsnag intercepts it without possibility to capture it and show custom error page to the user.
Steps to reproduce
Version
bugsnag-php v3.12.1
php-fpm 7.2.2
The text was updated successfully, but these errors were encountered: