Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Fatal error: Method class@anonymous::__toString() must not throw an exception after composer install

hello I have an error when I do a composer install and which does cache: clear.

  • I use Symfony 4.1
  • I already delete /var & /vendor
  • I am on Docker (php)

composer install
Loading composer repositories with package information
Installing dependencies (including require-dev) from lock file
Nothing to install or update
Package doctrine/reflection is abandoned, you should avoid using it. Use roave/better-reflection instead.
Package fzaninotto/faker is abandoned, you should avoid using it. No replacement was suggested.
Package symfony/lts is abandoned, you should avoid using it. Use symfony/flex instead.
Package symfony/webpack-encore-pack is abandoned, you should avoid using it. Use symfony/webpack-encore-bundle instead.
Package zendframework/zend-code is abandoned, you should avoid using it. Use laminas/laminas-code instead.
Package zendframework/zend-eventmanager is abandoned, you should avoid using it. Use laminas/laminas-eventmanager instead.
Generating autoload files
composer/package-versions-deprecated: Generating version class...
composer/package-versions-deprecated: ...done generating version class
102 packages you are using are looking for funding.
Use the `composer fund` command to find out more!

Run composer recipes at any time to see the status of your Symfony recipes.

Executing script cache:clear [KO]
 [KO]
Script cache:clear returned with error code 255
!!  Xdebug: [Config] Invalid mode '1' set for 'xdebug.mode' configuration setting (See: https://xdebug.org/docs/errors#CFG-C-MODE)
!!  
!!  Fatal error: Method class@anonymous::__toString() must not throw an exception, caught Symfony\Component\DependencyInjection\Exception\AutowiringFailedException:  in /var/www/symfony/vendor/symfony/dependency-injection/Compiler/AutowirePass.php on line 236
!!  
!!  Call Stack:
!!      0.0004     403344   1. {main}() /var/www/symfony/bin/console:0
!!      0.1875    2144496   2. Symfony\Bundle\FrameworkBundle\Console\Application->run($input = class Symfony\Component\Console\Input\ArgvInput 
!!      5.8396   32162400  18. Symfony\Component\DependencyInjection\Compiler\AutowirePass->Symfony\Component\DependencyInjection\Compiler\{closure:/var/www/symfony/vendor/symfony/dependency-injection/Compiler/AutowirePass.php:229-241}() /var/www/symfony/vendor/symfony/dependency-injection/Compiler/AutowirePass.php:261
!!  
!!  
!!  In AutowirePass.php line 236:
!!                                                                                 
!!    Error: Method class@anonymous::__toString() must not throw an exception, ca  
!!    ught Symfony\Component\DependencyInjection\Exception\AutowiringFailedExcept  
!!    ion:                                                                         
!!                                                                                 
!!  
!!  
Script @auto-scripts was called via post-install-cmd

I tried to follow this issue but nothing works (not work in develop for me)

My composer.json

{
    "type": "project",
    "license": "proprietary",
    "require": {
        "php": "^7.1.3",
        "ext-iconv": "*",
        "accord/mandrill-swiftmailer-bundle": "^1.3",
        "api-platform/api-pack": "^1.1",
        "composer/package-versions-deprecated": "1.11.99.1",
        "doctrine/doctrine-bundle": "^1.0",
        "doctrine/doctrine-migrations-bundle": "^2.2",
        "doctrine/orm": "^2.7",
        "friendsofsymfony/ckeditor-bundle": "^2.1",
        "friendsofsymfony/user-bundle": "~2.0",
        "knplabs/knp-paginator-bundle": "^4.0",
        "paragonie/random_compat": "^2.0",
        "ramsey/uuid-doctrine": "^1.4",
        "sensio/framework-extra-bundle": "^5.1",
        "sentry/sentry-symfony": "^3.1",
        "stof/doctrine-extensions-bundle": "^1.3",
        "symfony/asset": "^4.1",
        "symfony/console": "^4.1",
        "symfony/dotenv": "^4.1",
        "symfony/expression-language": "^4.1",
        "symfony/flex": "^1.0",
        "symfony/form": "^4.1",
        "symfony/framework-bundle": "^4.1",
        "symfony/lts": "^4@dev",
        "symfony/monolog-bundle": "^3.1",
        "symfony/process": "^4.1",
        "symfony/security-bundle": "^4.1",
        "symfony/serializer-pack": "*",
        "symfony/swiftmailer-bundle": "^3.1",
        "symfony/translation": "^4.1",
        "symfony/twig-bundle": "^4.1",
        "symfony/validator": "^4.1",
        "symfony/web-link": "^4.1",
        "symfony/webpack-encore-pack": "*",
        "symfony/yaml": "^4.1",
        "vich/uploader-bundle": "^1.9"
    },
    "require-dev": {
        "hautelook/alice-bundle": "^2.0",
        "doctrine/data-fixtures": "^1.3",
        "behat/behat": "^3.4",
        "symfony/debug-pack": "*",
        "symfony/maker-bundle": "^1.0",
        "symfony/phpunit-bridge": "^4.1",
        "symfony/profiler-pack": "*",
        "symfony/test-pack": "^1.0",
        "symfony/web-server-bundle": "^4.1"
    },
    "config": {
        "preferred-install": {
            "*": "dist"
        },
        "sort-packages": true
    },
    "autoload": {
        "psr-4": {
            "App\\": "src/"
        }
    },
    "autoload-dev": {
        "psr-4": {
            "App\\Tests\\": "tests/"
        }
    },
    "replace": {
        "symfony/polyfill-iconv": "*",
        "symfony/polyfill-php71": "*",
        "symfony/polyfill-php70": "*",
        "symfony/polyfill-php56": "*"
    },
    "scripts": {
        "auto-scripts": {
            "cache:clear": "symfony-cmd",
            "assets:install %PUBLIC_DIR%": "symfony-cmd"
        },
        "post-install-cmd": [
            "@auto-scripts"
        ],
        "post-update-cmd": [
            "@auto-scripts"
        ]
    },
    "conflict": {
        "symfony/symfony": "*"
    },
    "extra": {
        "symfony": {
            "allow-contrib": false
        }
    }
}

If anyone has even a stupid idea, I'll take it. I've been stuck on it for a long time ...

like image 714
Arnaud Bagnis Avatar asked Nov 26 '20 11:11

Arnaud Bagnis


2 Answers

This error happens because of new XDebug 3.0 incompatibility with Symfony framework

There are 2 possible ways to fix it:

  1. Use older version of XDebug:
  • Force install older version of xdebug sudo pecl install -f xdebug-2.9.8
  • Ensure extension is active by checking XDebug version in php -v output
  • Rebuild the SF cache bin/console cache:clear
  1. Temporary turn off XDebug and rebuild the cache (more like workaround):
  • Go into your docker container (or run following on your host machine, depending on your setup) using cli
  • Turn off debug export XDEBUG_MODE=off
  • Rebuild the cache bin/console cache:clear
  • Turn XDebug on again export XDEBUG_MODE=debug,develop (or whatever you use as mode)

Follow this issue to be updated about any other solutions

like image 86
Roman Avatar answered Feb 07 '23 01:02

Roman


Another solution could be to updated to PHP 7.4 which seems to work with XDEBUG 3

like image 33
Georg Ringer Avatar answered Feb 07 '23 01:02

Georg Ringer