Giter Site home page Giter Site logo

Illuminate\Contracts\Container\BindingResolutionException: Target [Illuminate\Contracts\Debug\ExceptionHandler] is not instantiable. about laravel-exceptions HOT 22 CLOSED

grahamcampbell avatar grahamcampbell commented on July 30, 2024
Illuminate\Contracts\Container\BindingResolutionException: Target [Illuminate\Contracts\Debug\ExceptionHandler] is not instantiable.

from laravel-exceptions.

Comments (22)

mihailo-misic avatar mihailo-misic commented on July 30, 2024 2

I had the same issue. (Using Laravel 5.2)
The problem was that i had a newer version of phpunit installed globally (5.4.4).
So by running phpunit command the global one was used.

Solutions:

  1. Use ./vendor/bin/phpunit instead;
  2. Downgrade the global phpunit, after which you can use the phpunit command regularly.
composer global remove phpunit/phpunit
composer global require 'phpunit/phpunit=~4.0'

Or just don't globally require PHPUnit.

Hope somebody finds this useful.

from laravel-exceptions.

GrahamCampbell avatar GrahamCampbell commented on July 30, 2024 1

Did you make sure to run php artisan config:cache?

from laravel-exceptions.

vinkla avatar vinkla commented on July 30, 2024

It is the other way around:

$app->singleton(
    Illuminate\Foundation\Exceptions\Handler::class,
    GrahamCampbell\Exceptions\ExceptionHandler::class
);

from laravel-exceptions.

vinkla avatar vinkla commented on July 30, 2024

Please see https://github.com/StyleCI/StyleCI/blob/182b1546d86e63c1ece33c13226557455ed5d732/bootstrap/app.php#L42

from laravel-exceptions.

tkprocat avatar tkprocat commented on July 30, 2024

So https://github.com/tkprocat/laravel-test-error/blob/master/bootstrap/app.php should be set up correctly?
That is currently giving an error when running phpUnit on the it.

from laravel-exceptions.

GrahamCampbell avatar GrahamCampbell commented on July 30, 2024

I can't replicate. It must be something wrong in your app.

from laravel-exceptions.

GrahamCampbell avatar GrahamCampbell commented on July 30, 2024

Also, make sure you use phpunit 4, laravel isn't compatible with phpunit 5.

from laravel-exceptions.

tkprocat avatar tkprocat commented on July 30, 2024

I'm running 4.8.21 under homestead.

Did you clone it and not get an error while running phpUnit?

from laravel-exceptions.

GrahamCampbell avatar GrahamCampbell commented on July 30, 2024

I use my own package in lots of projects both with phpunit 4 and 5, and it works just fine.

from laravel-exceptions.

GrahamCampbell avatar GrahamCampbell commented on July 30, 2024

Did you correctly install the package?

from laravel-exceptions.

GrahamCampbell avatar GrahamCampbell commented on July 30, 2024

You need to add the service provider near the top of the list of service providers, AND run php artisan config:cache, as needed every time you modify any config in laravel, AND run php artisan optimize --force to ensure your compiled.php file is up-to-date.

from laravel-exceptions.

tkprocat avatar tkprocat commented on July 30, 2024

I tried your description above and it didn't help anything. Just to test that the package was installed correctly I made a dummy exception route and it shows the page with id and it gets logged.

Just to be sure I've set things up correctly, can you give me a walkthrough of what needs to be changed on a freshly copy of laravel 5.2? Then I'll make a new project again tomorrow and remake the test to see if that helps.

from laravel-exceptions.

redgluten avatar redgluten commented on July 30, 2024

I’ve got this error on several Laravel 5.1 projects. I’ve followed every step suggested here, the service provider is the first called in the list and I’m using whoops 2.0 if it helps narrow the issue. Is there something else that could help you find the culprit?

It’s a great package by the way, thanks for the hard work. 👍

from laravel-exceptions.

redgluten avatar redgluten commented on July 30, 2024

Yes, I’ve ran every command listed here.

Here’s my list of providers minus those listed with the default Laravel install:

'providers' => [
        GrahamCampbell\Exceptions\ExceptionsServiceProvider::class,
        Collective\Html\HtmlServiceProvider::class,
        Intervention\Image\ImageServiceProvider::class,
        Mews\Purifier\PurifierServiceProvider::class,
        Maatwebsite\Excel\ExcelServiceProvider::class,
        Barryvdh\Debugbar\ServiceProvider::class,
        Spatie\LaravelAnalytics\LaravelAnalyticsServiceProvider::class,
]

My entire app\Exceptions\Handler:

<?php

namespace App\Exceptions;

use Exception;
use Illuminate\Database\Eloquent\ModelNotFoundException;
use Symfony\Component\HttpKernel\Exception\HttpException;
use Symfony\Component\HttpKernel\Exception\NotFoundHttpException;
use GrahamCampbell\Exceptions\ExceptionHandler as ExceptionHandler;

class Handler extends ExceptionHandler
{
    /**
     * A list of the exception types that should not be reported.
     *
     * @var array
     */
    protected $dontReport = [
        HttpException::class,
        ModelNotFoundException::class,
    ];
    /**
     * Report or log an exception.
     *
     * This is a great spot to send exceptions to Sentry, Bugsnag, etc.
     *
     * @param  \Exception  $e
     * @return void
     */
    public function report(Exception $e)
    {
        return parent::report($e);
    }
    /**
     * Render an exception into an HTTP response.
     *
     * @param  \Illuminate\Http\Request  $request
     * @param  \Exception  $e
     * @return \Illuminate\Http\Response
     */
    public function render($request, Exception $e)
    {
        if ($e instanceof ModelNotFoundException) {
            $e = new NotFoundHttpException($e->getMessage(), $e);
        }
        return parent::render($request, $e);
    }
}

And my composer.json requires:

    "require": {
        "php": ">=5.5.9",
        "laravel/framework": "5.1.*",
        "laravelcollective/html": "~5.1",
        "intervention/image": "2.1.*",
        "maatwebsite/excel": "~2.0.0",
        "guzzlehttp/guzzle": "~5.0",
        "mews/purifier": "~2.0",
        "spatie/laravel-analytics": "^1.1",
        "league/csv": "^8.0"
    },
    "require-dev": {
        "graham-campbell/exceptions": "~8.1",
        "fzaninotto/faker": "~1.5",
        "mockery/mockery": "0.9.*",
        "phpunit/phpunit": "~4.0",
        "phpspec/phpspec": "~2.1",
        "barryvdh/laravel-debugbar": "^2.1"
    },

from laravel-exceptions.

GrahamCampbell avatar GrahamCampbell commented on July 30, 2024

use GrahamCampbell\Exceptions\ExceptionHandler as ExceptionHandler;

You can drop the as ExceptionHandler.

    "graham-campbell/exceptions": "~8.1",

This absolutely MUST NOT go into require-dev. It MUST go in require, however, you should add whoops in require dev.

from laravel-exceptions.

GrahamCampbell avatar GrahamCampbell commented on July 30, 2024
    if ($e instanceof ModelNotFoundException) {
        $e = new NotFoundHttpException($e->getMessage(), $e);
    }

This code should be removed because this package already does that.

from laravel-exceptions.

GrahamCampbell avatar GrahamCampbell commented on July 30, 2024

Infact, you might as well just delete your exception handler, and bind ours in your bootstrap file.

from laravel-exceptions.

redgluten avatar redgluten commented on July 30, 2024

😑 Ok this is weird because I have many projects using your package and this is the only one where I made the mistake of putting it on the require-dev and forgot to add whoops.

So, my bad, but it doesn’t seems to be the issue here: it still gives me the error Illuminate\Contracts\Container\BindingResolutionException: Target [Illuminate\Contracts\Debug\ExceptionHandler] is not instantiable. when running phpunit.

Also:

if ($e instanceof ModelNotFoundException) {
    $e = new NotFoundHttpException($e->getMessage(), $e);
}

This code should be removed because this package already does that.

This is the exact same code from the latest Laravel 5.1 branch. Maybe the readme should be updated then?

And:

Infact, you might as well just delete your exception handler, and bind ours in your bootstrap file.

How should I do that exactly? Should I replace this with this:

$app->singleton(
    GrahamCampbell\Exceptions\ExceptionsServiceProvider::class,
    App\Exceptions\Handler::class
);

from laravel-exceptions.

GrahamCampbell avatar GrahamCampbell commented on July 30, 2024

How should I do that exactly? Should I replace this with this:

it's not working because you've setup the bindings wrong. You MUST leave the illuminate contract in.

from laravel-exceptions.

GrahamCampbell avatar GrahamCampbell commented on July 30, 2024
$app->singleton('Illuminate\Contracts\Debug\ExceptionHandler', 'GrahamCampbell\Exceptions\ExceptionHandler');

from laravel-exceptions.

redgluten avatar redgluten commented on July 30, 2024

I finally managed to make it work: it seems to be a problem with Phpunit versions: I had a global 5.2 phpunit while my project was using a 4.x version.

from laravel-exceptions.

DongJianWei24 avatar DongJianWei24 commented on July 30, 2024

@mihailomisic useful ! think you

from laravel-exceptions.

Related Issues (20)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.