framework: BindingResolutionException with ExceptionHandler
It looks like the ExceptionHandler has a problem with PHP Fatal Errors. I simply get a blank page and this shows up in the log:
PHP Fatal error:
Uncaught exception 'Illuminate\\Container\\BindingResolutionException' with message 'Target [Illuminate\\Contracts\\Debug\\ExceptionHandler] is not instantiable.'
in vendor/laravel/framework/src/Illuminate/Container/Container.php:756
Stack trace:
#0 vendor/laravel/framework/src/Illuminate/Container/Container.php(652): Illuminate\\Container\\Container->build('Illuminate\\\\Cont...', Array)
#1 vendor/laravel/framework/src/Illuminate/Foundation/Application.php(496): Illuminate\\Container\\Container->make('Illuminate\\\\Cont...', Array)
#2 vendor/laravel/framework/src/Illuminate/Foundation/Bootstrap/HandleExceptions.php(142): Illuminate\\Foundation\\Application->make('Illuminate\\\\Cont...')
#3 vendor/laravel/framework/src/Illuminate/Foundation/Bootstrap/HandleExceptions.php(73): Illuminate\\Foundation\\Bootstrap\\HandleExceptions->getExceptionHandler(
#4 in vendor/laravel/framework/src/Illuminate/Container/Container.php on line 756, referer: http://localhost/
About this issue
- Original URL
- State: closed
- Created 10 years ago
- Comments: 43 (13 by maintainers)
You’re doing it wrong.
@GrahamCampbell very nice, thank you.
Closing the issue with “You’re doing it wrong.” though – thats’s rather arrogant. When we cloned the l5 dev version, the IoC binding for
Illuminate\Contracts\Debug\ExceptionHandler
was missing frombootstrap/app.php
.If you’re not intimately familiar with a framework (or an updated version of a framework), the solution is not – at first glance – visible.
Thanks for posting your solution though. Abstracting out the displayer is a nice idea and I will do a similar approach.
As stated above @GrahamCampbell i don’t know why this hasn’t been re-opened, this is a pretty severe issue and obviously not fixed, there are several issues on this that when even closed people are still commenting they are engaging.
To my untrained eyes, this issue has been floating around for years.
Sorry if I’m being spam-my. I’m unsure where to post this.
PHPUnit 6.0.13 by Sebastian Bergmann and contributors.
Runtime: PHP 7.1.3 with Xdebug 2.5.0 Configuration: /home/rof/src/bitbucket.org/waypointbuilding_team/toto/phpunit.ci.xml
…E
Time: 10.05 seconds, Memory: 14.00MB
There was 1 error:
ERRORS! Tests: 12, Assertions: 237, Errors: 1.
@GrahamCampbell @taylorotwell I once again am strongly suggesting we re-open these issues, whatever is the particular problem people are having or if they’re “doing it wrong” is not the issue here. Look at everyones comments on their fixes and how there is barely any relation to the error.
The issue is the handler not properly finding/tracking/displaying what actually is going on. This is by far one of the most Achilles’ Heel’s types of bugs for any framework, and generally scares me that I have it running on production.
The solution is to upgrade your PHP to PHP 7 or later. I encountered this same issue and I resolved by upgrading to PHP 7.1
I encountered this issue when running phpunit tests. I turned off processIsolation in phpunit.xml and the issue resolved. Not sure why…
I am having this issue too. I have tried different phpunit versions from 4.8 to 5.7. Couldn’t fix it. In my local machine. I removed completely vendor folder and re-install everything. Laravel 5.4My bad, I forgot to call parent::setUp() on a TestCase, so all test setup was not being initialized. Maybe it helps someone.
Note to others who happen to land here:
check your phpunit version, L5.2 supports phpunit 4.8 if you use phpunit 5 you will get this error
https://github.com/laravel/framework/issues/10808
I encountered this problem when running tests with phpunit in laravel 5.0 and seems to be specific to laravel + phpunit.
My solution, which might be wrong, was to modify the provided
TestCase::setUp
andtearDown
methods.Now, in my
tests/TestCase.php
file,tearDown
is empty and mysetUp
looks like this:It works because
tearDown
flushed the app (with theExceptionHandler
binding frombootstrap/app.php
) so when phpunit actually got around to displaying the error it didn’t have a concrete implementation of the handler with which to display the errors.Anyway, this only happens in 5.0 and not in 5.1 (as far as a I can tell)
I’m surprised nothing has been done about this for 10 years, and yes, I’ve been experiencing this issue on/off for that long, but anyways here is a new discovery that hopefully leads to someone else fixing this bug.
I made this change:
This leads to my expected Exception stack being thrown in addition to the “Caused by PHPUnit\Framework\ExpectationFailedException” stack under it. It’s not desired to replace phpunit’s assertions with an exception, but there’s no explanation for why here and only here assertions cause
ExceptionHandler] is not instantiable.
.The main issue with the
BindingResolutionException ExceptionHandler is not instantiable.
bug is that it produces a stack that only includes laravel’s vendor code, so there is almost no way to figure out which test is causing it. Also, why does laravel try to instanciate ExceptionHandler for a failed phpunit assertion?My problem was with “codedungeon/phpunit-result-printer 0.20.1”, downgrade library to 0.19.* fix the problem.
@GrahamCampbell good talk!
Like every day I setup a fresh new test project from laravel and diff the app files…
What I did is the following (no idea at all if this is OK or best practice or if it even works):
Added an ErrorServiceProvider to App\Providers:
Added an ExceptionHandler to App\Library\Exception:
And then I registered my service provider in
config/app.php
in theproviders
array: