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

[Laravel] Target [Illuminate\Contracts\Debug\ExceptionHandler] is not instantiable. #7048

Closed
cay89 opened this issue Mar 25, 2025 · 7 comments

Comments

@cay89
Copy link
Contributor

cay89 commented Mar 25, 2025

API Platform version(s) affected: 4.1.3

Description

The recent fix solved the #7044 issue, but I still get a different error during installation:

PHP Fatal error:  Uncaught Illuminate\Contracts\Container\BindingResolutionException: Target [Illuminate\Contracts\Debug\ExceptionHandler] is not instantiable. in /app/vendor/laravel/framework/src/Illuminate/Container/Container.php:1216
@soyuka
Copy link
Member

soyuka commented Mar 25, 2025

Could you give me more informations? Can you try commenting this:

$this->app->singleton(
ExceptionHandlerInterface::class,
function (Application $app) {
/** @var ConfigRepository */
$config = $app['config'];
return new ErrorHandler(
$app,
$app->make(ResourceMetadataCollectionFactoryInterface::class),
$app->make(ApiPlatformController::class),
$app->make(IdentifiersExtractorInterface::class),
$app->make(ResourceClassResolverInterface::class),
$app->make(Negotiator::class),
$config->get('api-platform.exception_to_status'),
$config->get('app.debug')
);
}
);

Run your install again and let me know what's happening. I probably need to find a better way to extend the error handler.

@soyuka
Copy link
Member

soyuka commented Mar 25, 2025

I think this patch will help #7049 would you be able to try installing it?

@cay89
Copy link
Contributor Author

cay89 commented Mar 26, 2025

@soyuka I tried what you suggested, but it didn’t help.

This is a very strange issue. I’ve done a lot of debugging, but I haven’t gotten very far. I’ll describe what’s happening—maybe we can figure something out.

Basically, the error occurs when running php artisan package:discover. In my setup, this command doesn’t run automatically with composer install / composer update due to architectural reasons. Instead, I run it manually (or from an init script) after installation, once I’m sure the database and everything else are in place.

So, if I run it on version 4.1.3:

php artisan package:discover --ansi
PHP Fatal error:  Uncaught Illuminate\Contracts\Container\BindingResolutionException: Target [Illuminate\Contracts\Debug\ExceptionHandler] is not instantiable. in /app/vendor/laravel/framework/src/Illuminate/Container/Container.php:1216
Stack trace:
#0 /app/vendor/laravel/framework/src/Illuminate/Container/Container.php(968): Illuminate\Container\Container->notInstantiable('Illuminate\\Cont...')
#1 /app/vendor/laravel/framework/src/Illuminate/Container/Container.php(832): Illuminate\Container\Container->build('Illuminate\\Cont...')
#2 /app/vendor/laravel/framework/src/Illuminate/Foundation/Application.php(1078): Illuminate\Container\Container->resolve('Illuminate\\Cont...', Array, true)
#3 /app/vendor/laravel/framework/src/Illuminate/Container/Container.php(763): Illuminate\Foundation\Application->resolve('Illuminate\\Cont...', Array)
#4 /app/vendor/laravel/framework/src/Illuminate/Foundation/Application.php(1058): Illuminate\Container\Container->make('Illuminate\\Cont...', Array)
#5 /app/vendor/laravel/framework/src/Illuminate/Foundation/Bootstrap/HandleExceptions.php(289): Illuminate\Foundation\Application->make('Illuminate\\Cont...')
#6 /app/vendor/laravel/framework/src/Illuminate/Foundation/Bootstrap/HandleExceptions.php(208): Illuminate\Foundation\Bootstrap\HandleExceptions->getExceptionHandler()
#7 /app/vendor/laravel/framework/src/Illuminate/Foundation/Bootstrap/HandleExceptions.php(190): Illuminate\Foundation\Bootstrap\HandleExceptions->renderForConsole(Object(Illuminate\Contracts\Container\BindingResolutionException))
#8 /app/vendor/laravel/framework/src/Illuminate/Foundation/Bootstrap/HandleExceptions.php(256): Illuminate\Foundation\Bootstrap\HandleExceptions->handleException(Object(Illuminate\Contracts\Container\BindingResolutionException))
#9 [internal function]: Illuminate\Foundation\Bootstrap\HandleExceptions->Illuminate\Foundation\Bootstrap\{closure}(Object(Illuminate\Contracts\Container\BindingResolutionException))
#10 {main}
  thrown in /app/vendor/laravel/framework/src/Illuminate/Container/Container.php on line 1216
PHP Fatal error:  Uncaught Illuminate\Contracts\Container\BindingResolutionException: Target [Illuminate\Contracts\Debug\ExceptionHandler] is not instantiable. in /app/vendor/laravel/framework/src/Illuminate/Container/Container.php:1216
Stack trace:
#0 /app/vendor/laravel/framework/src/Illuminate/Container/Container.php(968): Illuminate\Container\Container->notInstantiable('Illuminate\\Cont...')
#1 /app/vendor/laravel/framework/src/Illuminate/Container/Container.php(832): Illuminate\Container\Container->build('Illuminate\\Cont...')
#2 /app/vendor/laravel/framework/src/Illuminate/Foundation/Application.php(1078): Illuminate\Container\Container->resolve('Illuminate\\Cont...', Array, true)
#3 /app/vendor/laravel/framework/src/Illuminate/Container/Container.php(763): Illuminate\Foundation\Application->resolve('Illuminate\\Cont...', Array)
#4 /app/vendor/laravel/framework/src/Illuminate/Foundation/Application.php(1058): Illuminate\Container\Container->make('Illuminate\\Cont...', Array)
#5 /app/vendor/laravel/framework/src/Illuminate/Foundation/Bootstrap/HandleExceptions.php(289): Illuminate\Foundation\Application->make('Illuminate\\Cont...')
#6 /app/vendor/laravel/framework/src/Illuminate/Foundation/Bootstrap/HandleExceptions.php(208): Illuminate\Foundation\Bootstrap\HandleExceptions->getExceptionHandler()
#7 /app/vendor/laravel/framework/src/Illuminate/Foundation/Bootstrap/HandleExceptions.php(190): Illuminate\Foundation\Bootstrap\HandleExceptions->renderForConsole(Object(Symfony\Component\ErrorHandler\Error\FatalError))
#8 /app/vendor/laravel/framework/src/Illuminate/Foundation/Bootstrap/HandleExceptions.php(232): Illuminate\Foundation\Bootstrap\HandleExceptions->handleException(Object(Symfony\Component\ErrorHandler\Error\FatalError))
#9 /app/vendor/laravel/framework/src/Illuminate/Foundation/Bootstrap/HandleExceptions.php(256): Illuminate\Foundation\Bootstrap\HandleExceptions->handleShutdown()
#10 [internal function]: Illuminate\Foundation\Bootstrap\HandleExceptions->Illuminate\Foundation\Bootstrap\{closure}()
#11 {main}
  thrown in /app/vendor/laravel/framework/src/Illuminate/Container/Container.php on line 1216

If I revert to version 4.1.1, it runs without any issues:

composer update
Loading composer repositories with package information                                                                                                                     Updating dependencies                                 
Lock file operations: 0 installs, 1 update, 0 removals
  - Downgrading api-platform/laravel (v4.1.3 => v4.1.1)
Writing lock file
Installing dependencies from lock file (including require-dev)
Package operations: 0 installs, 1 update, 0 removals
  - Downgrading api-platform/laravel (v4.1.3 => v4.1.1): Extracting archive
Generating optimized autoload files
> Illuminate\Foundation\ComposerScripts::postAutoloadDump
112 packages you are using are looking for funding.
Use the `composer fund` command to find out more!
No security vulnerability advisories found.
php artisan package:discover --ansi
   INFO  Discovering packages.  

  api-platform/laravel .................................................. DONE
  barryvdh/laravel-debugbar ............................................. DONE
  laravel/sail .......................................................... DONE
  laravel/tinker ........................................................ DONE
  lorisleiva/laravel-actions ............................................ DONE
  lorisleiva/lody ....................................................... DONE
  nesbot/carbon ......................................................... DONE
  nunomaduro/collision .................................................. DONE
  nunomaduro/termwind ................................................... DONE
  robsontenorio/laravel-keycloak-guard .................................. DONE
  spatie/laravel-data ................................................... DONE
  spatie/laravel-ignition ............................................... DONE
  spatie/php-structure-discoverer ....................................... DONE
  tightenco/ziggy ....................................................... DONE
  vladimir-yuldashev/laravel-queue-rabbitmq ............................. DONE

And here comes the interesting part!

If I revert to 4.1.3 (to break it again) and delete the api-platform/laravel package, the error still persists.

 composer update
Loading composer repositories with package information                                                                                                                     Updating dependencies                                 
Lock file operations: 0 installs, 1 update, 0 removals
  - Upgrading api-platform/laravel (v4.1.1 => v4.1.3)
Writing lock file
Installing dependencies from lock file (including require-dev)
Package operations: 0 installs, 1 update, 0 removals
  - Upgrading api-platform/laravel (v4.1.1 => v4.1.3): Extracting archive
Generating optimized autoload files
> Illuminate\Foundation\ComposerScripts::postAutoloadDump
112 packages you are using are looking for funding.
Use the `composer fund` command to find out more!
No security vulnerability advisories found.
php artisan package:discover --ansi
PHP Fatal error:  Uncaught Illuminate\Contracts\Container\BindingResolutionException: Target [Illuminate\Contracts\Debug\ExceptionHandler] is not instantiable. in /app/vendor/laravel/framework/src/Illuminate/Container/Container.php:1216
Stack trace:
...
composer remove api-platform/laravel
./composer.json has been updated
Running composer update api-platform/laravel
Loading composer repositories with package information
Updating dependencies
Lock file operations: 0 installs, 0 updates, 17 removals
  - Removing api-platform/documentation (v4.1.3)
  - Removing api-platform/hydra (v4.1.3)
  - Removing api-platform/json-api (v4.1.3)
  - Removing api-platform/json-hal (v4.1.3)
  - Removing api-platform/json-schema (v4.1.3)
  - Removing api-platform/jsonld (v4.1.3)
  - Removing api-platform/laravel (v4.1.3)
  - Removing api-platform/metadata (v4.1.3)
  - Removing api-platform/openapi (v4.1.3)
  - Removing api-platform/serializer (v4.1.3)
  - Removing api-platform/state (v4.1.3)
  - Removing psr/cache (3.0.0)
  - Removing psr/link (2.0.1)
  - Removing symfony/filesystem (v7.2.0)
  - Removing symfony/validator (v7.2.4)
  - Removing symfony/web-link (v7.2.0)
  - Removing willdurand/negotiation (3.1.0)
Writing lock file
Installing dependencies from lock file (including require-dev)
Package operations: 0 installs, 0 updates, 17 removals
  - Removing willdurand/negotiation (3.1.0)
  - Removing symfony/web-link (v7.2.0)
  - Removing symfony/validator (v7.2.4)
  - Removing symfony/filesystem (v7.2.0)
  - Removing psr/link (2.0.1)
  - Removing psr/cache (3.0.0)
  - Removing api-platform/state (v4.1.3)
  - Removing api-platform/serializer (v4.1.3)
  - Removing api-platform/openapi (v4.1.3)
  - Removing api-platform/metadata (v4.1.3)
  - Removing api-platform/laravel (v4.1.3)
  - Removing api-platform/jsonld (v4.1.3)
  - Removing api-platform/json-schema (v4.1.3)
  - Removing api-platform/json-hal (v4.1.3)
  - Removing api-platform/json-api (v4.1.3)
  - Removing api-platform/hydra (v4.1.3)
  - Removing api-platform/documentation (v4.1.3)
 0/7 [>---------------------------]   0%
 6/7 [========================>---]  85%
 7/7 [============================] 100%
Generating optimized autoload files
> Illuminate\Foundation\ComposerScripts::postAutoloadDump
109 packages you are using are looking for funding.
Use the `composer fund` command to find out more!
No security vulnerability advisories found.
php artisan package:discover --ansi
PHP Fatal error:  Uncaught Illuminate\Contracts\Container\BindingResolutionException: Target [Illuminate\Contracts\Debug\ExceptionHandler] is not instantiable. in /app/vendor/laravel/framework/src/Illuminate/Container/Container.php:1216
Stack trace:
...

If I then revert back to 4.1.1, it works again.

composer require api-platform/laravel:4.1.1
./composer.json has been updated
Running composer update api-platform/laravel
Loading composer repositories with package information                                                                                                                     Updating dependencies                                 
Lock file operations: 17 installs, 0 updates, 0 removals
  - Locking api-platform/documentation (v4.1.3)
  - Locking api-platform/hydra (v4.1.3)
  - Locking api-platform/json-api (v4.1.3)
  - Locking api-platform/json-hal (v4.1.3)
  - Locking api-platform/json-schema (v4.1.3)
  - Locking api-platform/jsonld (v4.1.3)
  - Locking api-platform/laravel (v4.1.1)
  - Locking api-platform/metadata (v4.1.3)
  - Locking api-platform/openapi (v4.1.3)
  - Locking api-platform/serializer (v4.1.3)
  - Locking api-platform/state (v4.1.3)
  - Locking psr/cache (3.0.0)
  - Locking psr/link (2.0.1)
  - Locking symfony/filesystem (v7.2.0)
  - Locking symfony/validator (v7.2.4)
  - Locking symfony/web-link (v7.2.0)
  - Locking willdurand/negotiation (3.1.0)
Writing lock file
Installing dependencies from lock file (including require-dev)
Package operations: 17 installs, 0 updates, 0 removals
    0 [>---------------------------]    0 [->--------------------------]
  - Installing willdurand/negotiation (3.1.0): Extracting archive
  - Installing psr/link (2.0.1): Extracting archive
  - Installing symfony/web-link (v7.2.0): Extracting archive
  - Installing psr/cache (3.0.0): Extracting archive
  - Installing api-platform/metadata (v4.1.3): Extracting archive
  - Installing api-platform/state (v4.1.3): Extracting archive
  - Installing symfony/validator (v7.2.4): Extracting archive
  - Installing api-platform/serializer (v4.1.3): Extracting archive
  - Installing symfony/filesystem (v7.2.0): Extracting archive
  - Installing api-platform/json-schema (v4.1.3): Extracting archive
  - Installing api-platform/openapi (v4.1.3): Extracting archive
  - Installing api-platform/jsonld (v4.1.3): Extracting archive
  - Installing api-platform/json-hal (v4.1.3): Extracting archive
  - Installing api-platform/documentation (v4.1.3): Extracting archive
  - Installing api-platform/json-api (v4.1.3): Extracting archive
  - Installing api-platform/hydra (v4.1.3): Extracting archive
  - Installing api-platform/laravel (v4.1.1): Extracting archive
  0/17 [>---------------------------]   0%
  8/17 [=============>--------------]  47%
 16/17 [==========================>-]  94%
 17/17 [============================] 100%
6 package suggestions were added by new dependencies, use `composer suggest` to see details.
Generating optimized autoload files
> Illuminate\Foundation\ComposerScripts::postAutoloadDump
112 packages you are using are looking for funding.
Use the `composer fund` command to find out more!
No security vulnerability advisories found.
 php artisan package:discover --ansi
 INFO  Discovering packages.  

  api-platform/laravel .................................................. DONE
  barryvdh/laravel-debugbar ............................................. DONE
  laravel/sail .......................................................... DONE
  laravel/tinker ........................................................ DONE
  lorisleiva/laravel-actions ............................................ DONE
  lorisleiva/lody ....................................................... DONE
  nesbot/carbon ......................................................... DONE
  nunomaduro/collision .................................................. DONE
  nunomaduro/termwind ................................................... DONE
  robsontenorio/laravel-keycloak-guard .................................. DONE
  spatie/laravel-data ................................................... DONE
  spatie/laravel-ignition ............................................... DONE
  spatie/php-structure-discoverer ....................................... DONE
  tightenco/ziggy ....................................................... DONE
  vladimir-yuldashev/laravel-queue-rabbitmq ............................. DONE

By the way, if I revert to 4.1.1 and then delete the package, it still fails.

It’s as if, even without Api Platform and under 4.1.3, it still tries to instantiate the interface—which, of course, it can’t...

@soyuka
Copy link
Member

soyuka commented Mar 26, 2025

But if you comment out the exception handler service it should work and you'll get a proper error.

@cay89
Copy link
Contributor Author

cay89 commented Mar 26, 2025

It should work, but it doesn't. Just if I revert to 4.1.1.

Image

@cay89
Copy link
Contributor Author

cay89 commented Mar 26, 2025

Awwww, I found a solution here: laravel/framework#51233 (comment)

My bootstrap/app.php configuration did not include the withExceptions() call, but for some reason, this hasn't caused any issues until now. The default Laravel application includes this.

@cay89 cay89 closed this as completed Mar 26, 2025
@soyuka
Copy link
Member

soyuka commented Mar 26, 2025

But if you comment the exception handler service it should work and you'll get a proper error.

Wow I'm so glad you found your issue thanks for the tries!!

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

2 participants