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

Making bullet work with Whoops exception library #38

Closed
mackenza opened this issue Mar 9, 2014 · 11 comments
Closed

Making bullet work with Whoops exception library #38

mackenza opened this issue Mar 9, 2014 · 11 comments

Comments

@mackenza
Copy link

mackenza commented Mar 9, 2014

This is more of a question than an "issue" ;)

I was interested in getting BulletPHP working with the Whoops https://github.com/filp/whoops exception library.

The code I tried so far was:

$whoops = new \Whoops\Run;
$whoops->pushHandler(new \Whoops\Handler\PrettyPageHandler);
$whoops->register();

$app = new Bullet\App();
$app->path('/', function($request) {
    return $blah;
});

This appears to work, in that it gives me a stack dump, seemingly Whoops-generated as so:

exception 'Whoops\Exception\ErrorException' with message 'Undefined variable: blah' in /var/sites/mysite/public/index.php:12
Stack trace:
    #0 /var/sites/mysite/public/index.php(12): Whoops\Run->handleError(8, 'Undefined varia...', '/var/sites/mysi...', 12, Array)
    #1 [internal function]: Closure->{closure}(Object(Bullet\Request))
    #2 /var/sites/mysite/vendor/vlucas/bulletphp/src/Bullet/App.php(262): call_user_func(Object(Closure), Object(Bullet\Request))
    #3 /var/sites/mysite/vendor/vlucas/bulletphp/src/Bullet/App.php(193): Bullet\App->_runPath('GET', '')
    #4 /var/sites/mysite/public/index.php(16): Bullet\App->run(Object(Bullet\Request))
    #5 {main}

but it's just that dump... no pretty page, no HTML at all. The dump pasted above is from the view source in the browser so it's only dumping the text itself.

I know this isn't part of BulletPHP but I was wondering if you had any thoughts on why this might not be working? I will probably ask the Whoops folks too.

@vlucas
Copy link
Owner

vlucas commented Mar 9, 2014

Looks like a very helpful library for debugging. I checked into it a bit. What happens when you set the writeToOutput flag to true?

$whoops->writeToOutput(true);

@mackenza
Copy link
Author

mackenza commented Mar 9, 2014

yeah, it's quite useful. I did some work with Laravel and he has it built in as the default exception handler in debug mode (which is a configuration setting).

I tried

$whoops->writeToOutput(true);

but the results were the same. I have been looking at this off and on for a couple of days and am baffled ;)

@vlucas
Copy link
Owner

vlucas commented Mar 9, 2014

Okay. There is some built-in exception handling in Bullet. You may have to do something in there:

$app->on('Exception', function($request, $response, \Exception $e) {
    // ...
    var_dump($e);
});

@mackenza
Copy link
Author

mackenza commented Mar 9, 2014

still no luck but thanks for the note about the exception handling.

I see you are using vardump() in your exception code. I have used this very nice replacement for vardump or print_r in the past called Kint https://github.com/raveren/kint/ . I know it adds a dependency to the package but it's probably worth it (imo).

@denis-sokolov
Copy link

Either pass the exception directly to Whoops:

$app->on('Exception', function($request, $response, \Exception $e) use ($run) {
    $run->handleException($e);
});

or restor the Whoops handler:

$run->register();
... $app ...
restore_exception_handler();

@denis-sokolov
Copy link

You can also register Whoops at the very end.

@mackenza
Copy link
Author

mackenza commented Mar 9, 2014

ok it's working.

I am using the following code (as suggested above):

<?php
require '../vendor/autoload.php';
$whoops = new \Whoops\Run;
$whoops->pushHandler(new \Whoops\Handler\PrettyPageHandler);
$whoops->register();

// Your App
$app = new Bullet\App();
$app->on('Exception', function($request, $response, \Exception $e) use ($whoops) {
    $whoops->handleException($e);
});

$app->path('/', function($request) {
    return $blah;
});

echo $app->run(new Bullet\Request());

@denis-sokolov - I notice that before the pretty formatting was working, my stack dump had 5 items but now that I have it working, there is just #0 …/­public/­index.php14. Is this expected or am I not quite there in getting this working?

Thanks for your help both of you!

@denis-sokolov
Copy link

I don't know, what's your error?

@mackenza
Copy link
Author

'Undefined variable: blah' in /var/sites/mysite/public/index.php:12

I was just testing it so I returned an undefined var to throw the exeception... I guess I could have done something more meaningful. The previous stack trace was in my OP

@sam2332
Copy link
Contributor

sam2332 commented Mar 26, 2014

is it because your not defining blah in your code? i dont see it in the code above....

@mackenza
Copy link
Author

@sam2332 yes, I was trying to trigger an error to test the whoops handler. My question was really why the stack trace was different between the pretty handler and the not quite working output I was getting before I defined the handler correctly. It's not a big deal.

@vlucas you can close this issue as I now have whoops working in bulletphp and the solution is in my post above.

@vlucas vlucas closed this as completed Mar 26, 2014
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

4 participants