symfony / symfony

The Symfony PHP framework
https://symfony.com
MIT License
29.8k stars 9.47k forks source link

Failed to generate ConfigBuilder for extension #45614

Closed captsulu closed 2 years ago

captsulu commented 2 years ago

Symfony version(s) affected

5.3.12

Description

When clearing cache or warming up cache I get the following warning messages in the cli.

15:16:56 WARNING   [app] Failed to generate ConfigBuilder for extension Symfony\Bundle\FrameworkBundle\DependencyInjection\FrameworkExtension. ["exception" => Symfony\Component\DependencyInjection\Exception\EnvNotFoundException^ { …},"extensionClass" => "Symfony\Bundle\FrameworkBundle\DependencyInjection\FrameworkExtension"]
15:16:56 WARNING   [app] Failed to generate ConfigBuilder for extension Sensio\Bundle\FrameworkExtraBundle\DependencyInjection\SensioFrameworkExtraExtension. ["exception" => Symfony\Component\DependencyInjection\Exception\EnvNotFoundException^ { …},"extensionClass" => "Sensio\Bundle\FrameworkExtraBundle\DependencyInjection\SensioFrameworkExtraExtension"]
15:16:56 WARNING   [app] Failed to generate ConfigBuilder for extension Doctrine\Bundle\DoctrineBundle\DependencyInjection\DoctrineExtension. ["exception" => Symfony\Component\DependencyInjection\Exception\EnvNotFoundException^ { …},"extensionClass" => "Doctrine\Bundle\DoctrineBundle\DependencyInjection\DoctrineExtension"]
15:16:56 WARNING   [app] Failed to generate ConfigBuilder for extension Doctrine\Bundle\MigrationsBundle\DependencyInjection\DoctrineMigrationsExtension. ["exception" => Symfony\Component\DependencyInjection\Exception\EnvNotFoundException^ { …},"extensionClass" => "Doctrine\Bundle\MigrationsBundle\DependencyInjection\DoctrineMigrationsExtension"]
15:16:56 WARNING   [app] Failed to generate ConfigBuilder for extension Symfony\Bundle\SecurityBundle\DependencyInjection\SecurityExtension. ["exception" => Symfony\Component\DependencyInjection\Exception\EnvNotFoundException^ { …},"extensionClass" => "Symfony\Bundle\SecurityBundle\DependencyInjection\SecurityExtension"]
15:16:56 WARNING   [app] Failed to generate ConfigBuilder for extension Symfony\Bundle\TwigBundle\DependencyInjection\TwigExtension. ["exception" => Symfony\Component\DependencyInjection\Exception\EnvNotFoundException^ { …},"extensionClass" => "Symfony\Bundle\TwigBundle\DependencyInjection\TwigExtension"]
15:16:56 WARNING   [app] Failed to generate ConfigBuilder for extension Twig\Extra\TwigExtraBundle\DependencyInjection\TwigExtraExtension. ["exception" => Symfony\Component\DependencyInjection\Exception\EnvNotFoundException^ { …},"extensionClass" => "Twig\Extra\TwigExtraBundle\DependencyInjection\TwigExtraExtension"]
15:16:56 WARNING   [app] Failed to generate ConfigBuilder for extension Symfony\Bundle\WebProfilerBundle\DependencyInjection\WebProfilerExtension. ["exception" => Symfony\Component\DependencyInjection\Exception\EnvNotFoundException^ { …},"extensionClass" => "Symfony\Bundle\WebProfilerBundle\DependencyInjection\WebProfilerExtension"]
15:16:56 WARNING   [app] Failed to generate ConfigBuilder for extension Symfony\Bundle\MonologBundle\DependencyInjection\MonologExtension. ["exception" => Symfony\Component\DependencyInjection\Exception\EnvNotFoundException^ { …},"extensionClass" => "Symfony\Bundle\MonologBundle\DependencyInjection\MonologExtension"]
15:16:56 WARNING   [app] Failed to generate ConfigBuilder for extension Symfony\Bundle\DebugBundle\DependencyInjection\DebugExtension. ["exception" => Symfony\Component\DependencyInjection\Exception\EnvNotFoundException^ { …},"extensionClass" => "Symfony\Bundle\DebugBundle\DependencyInjection\DebugExtension"]
15:16:56 WARNING   [app] Failed to generate ConfigBuilder for extension Symfony\Bundle\MakerBundle\DependencyInjection\MakerExtension. ["exception" => Symfony\Component\DependencyInjection\Exception\EnvNotFoundException^ { …},"extensionClass" => "Symfony\Bundle\MakerBundle\DependencyInjection\MakerExtension"]
15:16:56 WARNING   [app] Failed to generate ConfigBuilder for extension Symfony\Bundle\SwiftmailerBundle\DependencyInjection\SwiftmailerExtension. ["exception" => Symfony\Component\DependencyInjection\Exception\EnvNotFoundException^ { …},"extensionClass" => "Symfony\Bundle\SwiftmailerBundle\DependencyInjection\SwiftmailerExtension"]

How to reproduce

{
    "type": "project",
    "license": "proprietary",
    "minimum-stability": "stable",
    "prefer-stable": true,
    "require": {
        "php": ">=7.2.5",
        "ext-ctype": "*",
        "ext-iconv": "*",
        "ext-openssl": "^7.2",
        "authorizenet/authorizenet": "^2.0",
        "composer/package-versions-deprecated": "1.11.99.2",
        "doctrine/annotations": "^1.0",
        "doctrine/doctrine-bundle": "^2.4",
        "doctrine/doctrine-migrations-bundle": "^3.1",
        "doctrine/orm": "^2.9",
        "fpdf/fpdf": "^1.83",
        "google/apiclient": "^2.0",
        "iivanov/hotel-api-sdk-php": "^3.0",
        "league/flysystem": "^2.3",
        "paypal/paypal-checkout-sdk": "^1.0",
        "phpdocumentor/reflection-docblock": "^5.2",
        "phpoffice/phpspreadsheet": "^1.18",
        "rollerworks/password-strength-validator": "^1.4",
        "sensio/framework-extra-bundle": "^6.1",
        "stripe/stripe-php": "^7.98",
        "symfony/apache-pack": "^1.0",
        "symfony/asset": "5.3.*",
        "symfony/browser-kit": "5.3.*",
        "symfony/console": "5.3.*",
        "symfony/dotenv": "5.3.*",
        "symfony/expression-language": "5.3.*",
        "symfony/flex": "^1.3.1",
        "symfony/form": "5.3.*",
        "symfony/framework-bundle": "5.3.*",
        "symfony/http-client": "5.3.*",
        "symfony/intl": "5.3.*",
        "symfony/mailer": "5.3.*",
        "symfony/messenger": "5.3.*",
        "symfony/mime": "5.3.*",
        "symfony/monolog-bundle": "^3.1",
        "symfony/notifier": "5.3.*",
        "symfony/process": "5.3.*",
        "symfony/property-access": "5.3.*",
        "symfony/property-info": "5.3.*",
        "symfony/proxy-manager-bridge": "5.3.*",
        "symfony/runtime": "5.3.*",
        "symfony/security-bundle": "5.3.*",
        "symfony/serializer": "5.3.*",
        "symfony/string": "5.3.*",
        "symfony/swiftmailer-bundle": "^3.5",
        "symfony/translation": "5.3.*",
        "symfony/twig-bundle": "^5.3",
        "symfony/validator": "5.3.*",
        "symfony/web-link": "5.3.*",
        "symfony/yaml": "5.3.*",
        "twig/cssinliner-extra": "^3.3",
        "twig/extra-bundle": "^3.3",
        "twig/intl-extra": "^3.3",
        "twig/twig": "^2.12|^3.0"
    },
    "require-dev": {
        "phpunit/phpunit": "^8.5",
        "symfony/css-selector": "^5.3",
        "symfony/debug-bundle": "^5.3",
        "symfony/maker-bundle": "^1.0",
        "symfony/phpunit-bridge": "^5.3",
        "symfony/stopwatch": "^5.3",
        "symfony/var-dumper": "^5.3",
        "symfony/web-profiler-bundle": "^5.3"
    },
    "config": {
        "optimize-autoloader": true,
        "preferred-install": {
            "*": "dist"
        },
        "sort-packages": true
    },
    "autoload": {
        "psr-4": {
            "App\\": "src/"
        }
    },
    "autoload-dev": {
        "psr-4": {
            "App\\Tests\\": "tests/"
        }
    },
    "replace": {
        "symfony/polyfill-ctype": "*",
        "symfony/polyfill-iconv": "*",
        "symfony/polyfill-php72": "*"
    },
    "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,
            "require": "5.3.*"
        }
    }
}

Possible Solution

I attached my composer.json so you could look at the packages that I have installed to see if they are what may be cauing this issue.

Additional Context

As far as we can tell no operational impact at this time, but we are concerned that it may have an impact in the future as we migrate to a newer version of Symfony.

lyrixx commented 2 years ago

Hi.

I took you composer.json, and I tried it with php 7.4, and php 8.1 and I cannot reproduce your issue.

>/tmp/foobar php7.4 bin/console cache:clear -vvv

 // Clearing the cache for the dev environment with debug true                                                          

 // Warming up cache...                                                                                                 

 // Removing old build and cache directory...                                                                           

 // Finished                                                                                                            

 [OK] Cache for the "dev" environment (debug=true) was successfully cleared.                                            

>/tmp/foobar php7.4 bin/console cache:warmup -vvv

 // Warming up the cache for the dev environment with debug true                                                        

 [OK] Cache for the "dev" environment (debug=true) was successfully warmed.                                             

Could you create a reproducer to help us to fix this issue? thanks

xabbuh commented 2 years ago

I am going to close here for now due to the lack of feedback. Please let us know when you have more information and we can consider to reopen.

captsulu commented 2 years ago

I am sort of a newbie at this. I'll look through the rest of my yaml files to see if I have anything that is configured wrong that could be causing the problem.

On Wed, Mar 9, 2022 at 2:08 PM Christian Flothmann @.***> wrote:

I am going to close here for now due to the lack of feedback. Please let us know when you have more information and we can consider to reopen.

— Reply to this email directly, view it on GitHub https://github.com/symfony/symfony/issues/45614#issuecomment-1063263045, or unsubscribe https://github.com/notifications/unsubscribe-auth/ADAEPG4I3RELUEMEPINDEODU7DZMJANCNFSM5PXOXUKQ . Triage notifications on the go with GitHub Mobile for iOS https://apps.apple.com/app/apple-store/id1477376905?ct=notification-email&mt=8&pt=524675 or Android https://play.google.com/store/apps/details?id=com.github.android&referrer=utm_campaign%3Dnotification-email%26utm_medium%3Demail%26utm_source%3Dgithub.

You are receiving this because you authored the thread.Message ID: @.***>

--

Gregory Neely Mobile: 386-631-8311 opencloudstart.com Web Developer CNO financial

nature-web commented 2 years ago

HI, I have the same problem and i can't use php bin/console make:migration or symfony console make:migration i have an error who said Command "make:migration" is not defined.

captsulu commented 2 years ago

What I found it something in your config is misconfigured.

On Fri, Mar 18, 2022 at 5:47 PM nature-web @.***> wrote:

HI, I have the same problem and i can't use php bin/console make:migration or symfony console make:migration i have an error who said Command "make:migration" is not defined.

— Reply to this email directly, view it on GitHub https://github.com/symfony/symfony/issues/45614#issuecomment-1072841159, or unsubscribe https://github.com/notifications/unsubscribe-auth/ADAEPGZPNTMOULXLYGDODX3VAT2X7ANCNFSM5PXOXUKQ . Triage notifications on the go with GitHub Mobile for iOS https://apps.apple.com/app/apple-store/id1477376905?ct=notification-email&mt=8&pt=524675 or Android https://play.google.com/store/apps/details?id=com.github.android&referrer=utm_campaign%3Dnotification-email%26utm_medium%3Demail%26utm_source%3Dgithub.

You are receiving this because you authored the thread.Message ID: @.***>

--

Gregory Neely Mobile: 386-631-8311 opencloudstart.com Web Developer CNO financial

lfjeff commented 2 years ago

I had a very similar problem and was getting Failed to generate ConfigBuilder for extension errors when running certain bin/console commands. After spending several hours tracing through my code and Symfony code in an attempt to find the issue, I finally solved it by updating the bin/console file (I copied it from a recent fresh install of Symfony 5.4).

The site with this problem was originally created on Symfony 4 and had been updated to Symfony 5. While all the packages were updated, the actual bin/console file was still the original version. The old bin/console command handles the loading of .env variables differently than more recent versions and this was the cause of the error messages.

I was expecting the bin/console command to be automatically updated when the symfony/console package is updated, but apparently that is not how it works.

igormukhingmailcom commented 2 years ago
kevinpapst commented 2 years ago

Same issue here. For me it was in an upgraded SF4 LTS to SF5 LTS project: Environment variable not found: "APP_SECRET".

Upgrading bin/console to use the new runtime component did not fix anything here, but still is a good idea.

Thanks to @igormukhingmailcom for the simple idea! The exception message should include the original exception message. See CacheWarmer/ConfigBuilderCacheWarmer.php around line 59.

Simply add $e->getMessage() to the log message to find the real reason:

$this->logger->warning('Failed to generate ConfigBuilder for extension {extensionClass}.' . $e->getMessage(), ['exception' => $e, 'extensionClass' => \get_class($extension)]);
stof commented 2 years ago

Well, the log context includes the original exception.

nicolas-grekas commented 2 years ago

We could still replicate the message up in the chain to make it easier to see I think. @kevinpapst up for a PR doing so?

kevinpapst commented 2 years ago

@nicolas-grekas Sure. The message is the only way to see the causing issue and it believe missing ENVs might happen from time to time, not only for us who posted here ;-)

You know what is troubling me: even though cache warmup failed, the app worked totally fine. And the logs contained one message for every registered bundle, while the only place where APP_SECRET is accessed is in the framework.secret config and therefor in the container build process:

15:17:49 WARNING   [app] Failed to generate ConfigBuilder for extension Symfony\Bundle\FrameworkBundle\DependencyInjection\FrameworkExtension. ["exception" => Symfony\Component\DependencyInjection\Exception\EnvNotFoundException { …},"extensionClass" => "Symfony\Bundle\FrameworkBundle\DependencyInjection\FrameworkExtension"]
15:17:49 WARNING   [app] Failed to generate ConfigBuilder for extension Symfony\Bundle\TwigBundle\DependencyInjection\TwigExtension. ["exception" => Symfony\Component\DependencyInjection\Exception\EnvNotFoundException { …},"extensionClass" => "Symfony\Bundle\TwigBundle\DependencyInjection\TwigExtension"]
15:17:49 WARNING   [app] Failed to generate ConfigBuilder for extension Symfony\Bundle\SecurityBundle\DependencyInjection\SecurityExtension. ["exception" => Symfony\Component\DependencyInjection\Exception\EnvNotFoundException { …},"extensionClass" => "Symfony\Bundle\SecurityBundle\DependencyInjection\SecurityExtension"]
15:17:49 WARNING   [app] Failed to generate ConfigBuilder for extension Doctrine\Bundle\DoctrineBundle\DependencyInjection\DoctrineExtension. ["exception" => Symfony\Component\DependencyInjection\Exception\EnvNotFoundException { …},"extensionClass" => "Doctrine\Bundle\DoctrineBundle\DependencyInjection\DoctrineExtension"]
15:17:49 WARNING   [app] Failed to generate ConfigBuilder for extension Doctrine\Bundle\MigrationsBundle\DependencyInjection\DoctrineMigrationsExtension. ["exception" => Symfony\Component\DependencyInjection\Exception\EnvNotFoundException { …},"extensionClass" => "Doctrine\Bundle\MigrationsBundle\DependencyInjection\DoctrineMigrationsExtension"]
15:17:49 WARNING   [app] Failed to generate ConfigBuilder for extension Symfony\Bundle\MonologBundle\DependencyInjection\MonologExtension. ["exception" => Symfony\Component\DependencyInjection\Exception\EnvNotFoundException { …},"extensionClass" => "Symfony\Bundle\MonologBundle\DependencyInjection\MonologExtension"]
15:17:49 WARNING   [app] Failed to generate ConfigBuilder for extension Sensio\Bundle\FrameworkExtraBundle\DependencyInjection\SensioFrameworkExtraExtension. ["exception" => Symfony\Component\DependencyInjection\Exception\EnvNotFoundException { …},"extensionClass" => "Sensio\Bundle\FrameworkExtraBundle\DependencyInjection\SensioFrameworkExtraExtension"]
15:17:49 WARNING   [app] Failed to generate ConfigBuilder for extension Symfony\WebpackEncoreBundle\DependencyInjection\WebpackEncoreExtension. ["exception" => Symfony\Component\DependencyInjection\Exception\EnvNotFoundException { …},"extensionClass" => "Symfony\WebpackEncoreBundle\DependencyInjection\WebpackEncoreExtension"]
15:17:49 WARNING   [app] Failed to generate ConfigBuilder for extension Twig\Extra\TwigExtraBundle\DependencyInjection\TwigExtraExtension. ["exception" => Symfony\Component\DependencyInjection\Exception\EnvNotFoundException { …},"extensionClass" => "Twig\Extra\TwigExtraBundle\DependencyInjection\TwigExtraExtension"]
15:17:49 WARNING   [app] Failed to generate ConfigBuilder for extension BabDev\PagerfantaBundle\DependencyInjection\BabDevPagerfantaExtension. ["exception" => Symfony\Component\DependencyInjection\Exception\EnvNotFoundException { …},"extensionClass" => "BabDev\PagerfantaBundle\DependencyInjection\BabDevPagerfantaExtension"]

So I wonder if the log issue is the correct place to look at or if missing ENV should be reported otherwise?

botjaeger commented 2 years ago
  • Had tons of Failed to generate ConfigBuilder for extension
  • Found this phrase at ConfigBuilderCacheWarmer
  • After commenting out exception catching like this:

    //            try {
                  $this->dumpExtension($extension, $generator);
    //            } catch (\Exception $e) {
    //                if ($this->logger) {
    //                    $this->logger->warning('Failed to generate ConfigBuilder for extension {extensionClass}.', ['exception' => $e, 'extensionClass' => \get_class($extension)]);
    //                }
    //            }

    and running bin/console cache:warmup I've got true the reason:

    In EnvVarProcessor.php line 172:
    Environment variable not found: "BLA_BLA_BLA". 
  • So, to fix annoying Failed to generate ConfigBuilder for extension messages I had to just add accidentally missed BLA_BLA_BLA= to .env

I literally just logged in just to say thank you!

predyke commented 2 years ago
  • Had tons of Failed to generate ConfigBuilder for extension
  • Found this phrase at ConfigBuilderCacheWarmer
  • After commenting out exception catching like this:

    //            try {
                  $this->dumpExtension($extension, $generator);
    //            } catch (\Exception $e) {
    //                if ($this->logger) {
    //                    $this->logger->warning('Failed to generate ConfigBuilder for extension {extensionClass}.', ['exception' => $e, 'extensionClass' => \get_class($extension)]);
    //                }
    //            }

    and running bin/console cache:warmup I've got true the reason:

    In EnvVarProcessor.php line 172:
    Environment variable not found: "BLA_BLA_BLA". 
  • So, to fix annoying Failed to generate ConfigBuilder for extension messages I had to just add accidentally missed BLA_BLA_BLA= to .env

You sir saved my day! Thank you!

stof commented 2 years ago

The Failed to generate ConfigBuilder for extension log warning includes the exception in the context, so you should have access to the exception message in your logs though.

predyke commented 2 years ago

The Failed to generate ConfigBuilder for extension log warning includes the exception in the context, so you should have access to the exception message in your logs though.

What caused me the confusion personally is that I was only looking at the warning log in symfony server. After actually checking ConfigBuilderCacheWarmer I realised it is properly logged with the context.

igormukhingmailcom commented 2 years ago

One more thing related to missed env var.

If you're working with Sylius and missed some env var at your .env, you will find this exception:

[Sylius\Bundle\FixturesBundle\Suite\SuiteNotFoundException]
  Suite with name "some_suite" could not be found!

when running symfony console sylius:fixtures:load some_suite -n.

Probably in case when you're using some of that missed env vars at your fixture suite configuration.

Tofandel commented 2 years ago

Can we replace the log to $this->logger?->warning('Failed to generate ConfigBuilder for extension {extensionClass}.', ['exception' => $e->getMessage(), 'extensionClass' => \get_class($extension)]);

Currently the exception message is not visible

carlospauluk commented 1 year ago

Hi, once I got this problem because in my services.yaml I had some parameters that wasnt on my .env files . Check that!

tounaf commented 1 year ago

Optionnaly , To have full detail of this exception , we can use option -vvv in the command . This option is rather natural .

uncaught commented 1 year ago

I find it weird that I have to supply all environment variables upon build time to not get warnings. Env-vars are supposed to be runtime vars.

So if I have to set all env parameters to empty defaults, what's the point of this warning? What is it warning me of? I still don't get a warning if I forget to set the env var on the production server at runtime.