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

Bugsnag exception handler causes CLI scripts to exit 0 with uncaught exceptions #523

Closed
blkperl opened this issue Apr 4, 2019 · 5 comments · Fixed by #610
Closed

Bugsnag exception handler causes CLI scripts to exit 0 with uncaught exceptions #523

blkperl opened this issue Apr 4, 2019 · 5 comments · Fixed by #610
Labels
bug Confirmed bug released This feature/bug fix has been released

Comments

@blkperl
Copy link

blkperl commented Apr 4, 2019

Description

Bugsnag exception handler causes CLI scripts to exit 0 with uncaught exceptions

Issue

Bugsnag exception handler causes CLI scripts to exit 0 with uncaught exceptions

Environment

  • bugsnag-php version: v3.16.0
  • PHP version: 7.2
  • What web framework are you using, if any?: None
  • How are you installing bugsnag-php? (Composer, phar files?): composer
  • Operating system name and version: Ubuntu 16.04

Example code snippet

How to reproduce the issue

<?php
declare(strict_types=1);

require __DIR__ . '/vendor/autoload.php';


$bugsnagClient = \Bugsnag\Client::make('foo');
\Bugsnag\Handler::registerWithPrevious($bugsnagClient);
throw new Exception();
$ php test.php
$ echo $?
0

How to workaround the issue

$ cat test.php
<?php
declare(strict_types=1);

require __DIR__ . '/vendor/autoload.php';


$bugsnagClient = \Bugsnag\Client::make('foo');

set_exception_handler(function ($throwable) {
      throw $throwable;
});

\Bugsnag\Handler::registerWithPrevious($bugsnagClient);
throw new Exception();
$ php test.php
PHP Fatal error:  Uncaught Exception in test.php:14
Stack trace:
#0 {main}
  thrown in test.php on line 14

Fatal error: Uncaught Exception in test.php on line 14

Exception:  in test.php on line 14

Call Stack:
    0.0240    2079608   1. Bugsnag\Handler->exceptionHandler() REDACTED/vendor/bugsnag/bugsnag/src/Handler.php:0
    0.0282    2200056   2. call_user_func:{REDACTED/vendor/bugsnag/bugsnag/src/Handler.php:155}() REDACTED/vendor/bugsnag/bugsnag/src/Handler.php:155
    0.0282    2200056   3. {closure:test.php:9-11}() REDACTED/vendor/bugsnag/bugsnag/src/Handler.php:155

$ echo $?
255
@tomlongridge tomlongridge added the needs discussion Requires internal analysis/discussion label Aug 29, 2019
@glennpratt
Copy link

I have the same issue, this has now bitten me multiple times.

@xljones
Copy link

xljones commented Feb 27, 2020

Hi @glennpratt, have you tried using the workaround in @blkperl's issue report using set_exception_handler()? You may also be interested in reading the comments in #475 as to why this is happening. --Xander

@glennpratt
Copy link

Yes @xander-jones thanks. I have read all the issues, though the contention that this is normal behavior is rather off to me. I've been working with PHP for a very long time and maintaining sane behavior when settings these handlers has always seemed a given to me.

Here's yesterdays banging my head against a wall and implementing this in another project:

// Workaround https://github.com/bugsnag/bugsnag-php/issues/523 which causes all PHP
// exceptions to be swallowed and exit 0.
$previousHandler = null;
$previousHandler = set_exception_handler(function ($throwable) use (&$previousHandler): void {
    if ($previousHandler !== null) {
        call_user_func($previousHandler, $throwable);
    }
    throw $throwable;
});
Bugsnag\Handler::registerWithPrevious(self::$bugsnagClient);

@bugsnagbot bugsnagbot added the scheduled Work is starting on this feature/bug label Jul 8, 2020
@xljones xljones removed the needs discussion Requires internal analysis/discussion label Jul 31, 2020
@imjoehaines
Copy link
Contributor

This should now be fixed in v3.23.1

@johnkiely1 johnkiely1 added bug Confirmed bug released This feature/bug fix has been released and removed scheduled Work is starting on this feature/bug labels Oct 20, 2020
@glennpratt
Copy link

Thanks @imjoehaines!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Confirmed bug released This feature/bug fix has been released
Projects
None yet
Development

Successfully merging a pull request may close this issue.

7 participants