-
Notifications
You must be signed in to change notification settings - Fork 409
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
Flight is removing my custom error_handler #275
Comments
Can you show how do you exactly define your error handler? I personally use https://github.com/filp/whoops to handle errors (so I turn flight error handling off), and my code that actually works looks like this (it's very simple and no extra): use Whoops\Run;
use Whoops\Handler\PrettyPageHandler;
$whoops = new Run;
$whoops->pushHandler(new PrettyPageHandler);
$whoops->register();
Flight::set('flight.handle_errors', false); |
Sure, here is my code:
If I initialize (again!) my handler in my controller ctor, it works fine and handles errors (because my controller is called near the end of the Flight |
I see. Try remove function allThrowErrorHandler($errNo, $errStr, $errFile, $errLine)
{
die('test'); // This code is never called
}
set_error_handler('allThrowErrorHandler'); to this: Flight::map('error', function(Exception $e){
die('test'); // This code is never called
}); This should work. |
You mean even with |
@RenaudParis no, just updated my answer :) |
@RenaudParis were you able to make it work? |
@tamtamchik Thank you for the code snippet. Here is my code: // in "app->initFlightErrorHandler()":
\Flight::map('error', array($this, 'onFlightError'));
$toto = $tata; // cause a notice, that should be caught and converted into an exception (at least that's what I would like to achieve with my own error handler)
// "app->onFlightError':
public function onFlightError(\Exception $e)
{
var_dump($e);
die('error ' . $e->getMessage());
} |
It sounds like I need to check if the currently set error handlers are Flight's own handlers before running restore handler functions. I'll do some testing. |
Any updates? I'm running into the same issue. $whoops = new \Whoops\Run;
$whoops->pushHandler(new \Whoops\Handler\PrettyPageHandler);
$whoops->register();
Flight::set('flight.handle_errors', false); Error handler is now default php handler and not whoops. (PHP 7.1) |
Maybe I found the problem... So From php.net/restore_error_handler:
So it actually reverts my own registered error handler - and I am back to PHPs default error handler... I think the two function calls aren't necessary. After commenting out line 133&134 my error handler is working fine. |
@CodeBrauer I think you're right. I'll provide a fix. |
Fixed in 5b4916d. |
Because of this code below (in addition to using
\Flight::set('flight.handle_errors', false);
):Flight is removing my custom error_handler that I defined before calling
Flight::start()
(because it would have no sense to define it after this call)I could not override the Engine (at least I tried using
Flight::register
but it did not work).And I could not override Flight itself so that I could manually override the
$engine
property (which is set usingself::$engine = new new \flight\Engine();
), because the propery is private.Extending the whole
\Flight
class obviously causes disastrous damage.Also, using an "after start" callback is of no use because the error arises during start(), not after.
I don't know what else to do, but I cannot have uncaught errors in my app :(
The only option for me is to define my error_handler during the construct of my controller (called by the router), but ideally I'd rather define my error_handler at the very beginning of my application code.
Thanks for any tips, or for replacing the above code with something like:
(I don't know if it will cause other issues though, but at least it will not remove any previously set error_handler)
Sincerely,
The text was updated successfully, but these errors were encountered: