Skip to content

lint:container --resolve-env-vars fails on new project #59028

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

Open
tacman opened this issue Nov 28, 2024 · 6 comments
Open

lint:container --resolve-env-vars fails on new project #59028

tacman opened this issue Nov 28, 2024 · 6 comments
Labels
Bug DependencyInjection Help wanted Issues and PRs which are looking for volunteers to complete them. Status: Needs Review

Comments

@tacman
Copy link
Contributor

tacman commented Nov 28, 2024

Symfony version(s) affected

7.2

Description

Resolved value of "default:kernel.runtime_mode:" did not result in an array value.

image

How to reproduce

symfony new --webapp env-var-demo
cd  env-var-demo
bin/console lint:container --resolve-env-vars
@GromNaN
Copy link
Member

GromNaN commented Nov 29, 2024

Thank you for testing and finding this issue. The option --resolve-env-vars is a new feature introduced by #58199 by @ostrolucky.

The error is due to some default parameters in the Kernel class:

'kernel.runtime_environment' => '%env(default:kernel.environment:APP_RUNTIME_ENV)%',
'kernel.runtime_mode' => '%env(query_string:default:container.runtime_mode:APP_RUNTIME_MODE)%',
'kernel.runtime_mode.web' => '%env(bool:default::key:web:default:kernel.runtime_mode:)%',
'kernel.runtime_mode.cli' => '%env(not:default:kernel.runtime_mode.web:)%',
'kernel.runtime_mode.worker' => '%env(bool:default::key:worker:default:kernel.runtime_mode:)%',

The full exception trace is:

In EnvVarProcessor.php line 81:
                                                                                      
  [Symfony\Component\DependencyInjection\Exception\RuntimeException]                  
  Resolved value of "default:kernel.runtime_mode:" did not result in an array value.  
                                                                                      

Exception trace:
at src/Symfony/Component/DependencyInjection/EnvVarProcessor.php:81
 Symfony\Component\DependencyInjection\EnvVarProcessor->getEnv() at src/Symfony/Component/DependencyInjection/Container.php:370
 Symfony\Component\DependencyInjection\Container->getEnv() at src/Symfony/Component/DependencyInjection/ContainerBuilder.php:1667
 Symfony\Component\DependencyInjection\ContainerBuilder->getEnv() at src/Symfony/Component/DependencyInjection/EnvVarProcessor.php:132
 Symfony\Component\DependencyInjection\EnvVarProcessor->getEnv() at src/Symfony/Component/DependencyInjection/Container.php:370
 Symfony\Component\DependencyInjection\Container->getEnv() at src/Symfony/Component/DependencyInjection/ContainerBuilder.php:1667
 Symfony\Component\DependencyInjection\ContainerBuilder->getEnv() at src/Symfony/Component/DependencyInjection/EnvVarProcessor.php:169
 Symfony\Component\DependencyInjection\EnvVarProcessor->getEnv() at src/Symfony/Component/DependencyInjection/Container.php:370
 Symfony\Component\DependencyInjection\Container->getEnv() at src/Symfony/Component/DependencyInjection/ContainerBuilder.php:1667
 Symfony\Component\DependencyInjection\ContainerBuilder->getEnv() at src/Symfony/Component/DependencyInjection/ContainerBuilder.php:1496
 Symfony\Component\DependencyInjection\ContainerBuilder->resolveEnvPlaceholders() at src/Symfony/Component/DependencyInjection/Compiler/ResolveEnvPlaceholdersPass.php:26
 Symfony\Component\DependencyInjection\Compiler\ResolveEnvPlaceholdersPass->processValue() at src/Symfony/Component/DependencyInjection/Compiler/AbstractRecursivePass.php:84
 Symfony\Component\DependencyInjection\Compiler\AbstractRecursivePass->processValue() at src/Symfony/Component/DependencyInjection/Compiler/ResolveEnvPlaceholdersPass.php:38
 Symfony\Component\DependencyInjection\Compiler\ResolveEnvPlaceholdersPass->processValue() at src/Symfony/Component/DependencyInjection/Compiler/AbstractRecursivePass.php:93
 Symfony\Component\DependencyInjection\Compiler\AbstractRecursivePass->processValue() at src/Symfony/Component/DependencyInjection/Compiler/ResolveEnvPlaceholdersPass.php:38
 Symfony\Component\DependencyInjection\Compiler\ResolveEnvPlaceholdersPass->processValue() at src/Symfony/Component/DependencyInjection/Compiler/AbstractRecursivePass.php:84
 Symfony\Component\DependencyInjection\Compiler\AbstractRecursivePass->processValue() at src/Symfony/Component/DependencyInjection/Compiler/ResolveEnvPlaceholdersPass.php:38
 Symfony\Component\DependencyInjection\Compiler\ResolveEnvPlaceholdersPass->processValue() at src/Symfony/Component/DependencyInjection/Compiler/AbstractRecursivePass.php:45
 Symfony\Component\DependencyInjection\Compiler\AbstractRecursivePass->process() at src/Symfony/Component/DependencyInjection/Compiler/Compiler.php:73
 Symfony\Component\DependencyInjection\Compiler\Compiler->compile() at src/Symfony/Component/DependencyInjection/ContainerBuilder.php:801
 Symfony\Component\DependencyInjection\ContainerBuilder->compile() at src/Symfony/Bundle/FrameworkBundle/Command/ContainerLintCommand.php:63
 Symfony\Bundle\FrameworkBundle\Command\ContainerLintCommand->execute() at src/Symfony/Component/Console/Command/Command.php:279
 Symfony\Component\Console\Command\Command->run() at src/Symfony/Component/Console/Application.php:1045

@GromNaN GromNaN added the Help wanted Issues and PRs which are looking for volunteers to complete them. label Nov 29, 2024
@GromNaN
Copy link
Member

GromNaN commented Dec 7, 2024

This unit test reproduces the issue:

<?php

use PHPUnit\Framework\TestCase;
use Symfony\Component\DependencyInjection\ContainerBuilder;

class Issue59028 extends TestCase
{
    public function test()
    {
        $container = new ContainerBuilder();
        $container->setParameter('container.runtime_mode', 'test');
        $container->setParameter('kernel.runtime_mode', '%env(query_string:default:container.runtime_mode:APP_RUNTIME_MODE)%');
        $container->resolveEnvPlaceholders('%env(default::key:web:default:kernel.runtime_mode:)%', true);
    }
}

@Myks92
Copy link
Contributor

Myks92 commented Dec 15, 2024

I am also experiencing this issue

@tacman
Copy link
Contributor Author

tacman commented Dec 15, 2024

@ostrolucky can you take a look at this when you get a chance? It seems like a pretty cool feature!

@MatTheCat
Copy link
Contributor

MatTheCat commented Jan 20, 2025

Resolving env vars means you have to resolve parameters as well to make the default (and resolve) env var processor work, but #34784 marked the parameter bag resolved before the compilation.

@Myks92
Copy link
Contributor

Myks92 commented Feb 26, 2025

Is there a solution?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Bug DependencyInjection Help wanted Issues and PRs which are looking for volunteers to complete them. Status: Needs Review
Projects
None yet
Development

No branches or pull requests

5 participants