symfony: Don't throw fatal errors for unused env vars
Q | A |
---|---|
Bug report? | no |
Feature request? | yes |
BC Break report? | no |
RFC? | yes |
Symfony version | 3.3.x |
While upgrading an app to Symfony 3.3 + Symfony Flex, I’m facing some issues. All of them look reasonable to me, except this one:
Fatal error: Uncaught Symfony\Component\DependencyInjection\Exception\EnvParameterException:
Environment variables "DATABASE_URL" are never used. Please, check your
container's configuration.
I think it’s crazy to throw a fatal error just because I’m not using a defined env var. Could we please change this behavior? Thanks!
About this issue
- Original URL
- State: closed
- Created 7 years ago
- Reactions: 31
- Comments: 23 (19 by maintainers)
Commits related to this issue
- bug #23903 [DI] Fix merging of env vars in configs (nicolas-grekas) This PR was merged into the 3.3 branch. Discussion ---------- [DI] Fix merging of env vars in configs | Q | A | ----... — committed to symfony/symfony by nicolas-grekas 7 years ago
- bug #24009 [DI] Fix tracking env vars when merging configs (bis) (nicolas-grekas) This PR was merged into the 3.3 branch. Discussion ---------- [DI] Fix tracking env vars when merging configs (bis)... — committed to symfony/symfony by fabpot 7 years ago
- Resolve environment placeholders When using environment variables as values for config parameters that are read conditionally, symfony can mark that environment variable as unused and throw a fatal e... — committed to bastnic/flysystem-bundle by bastnic 4 years ago
I think I agree with @javiereguiluz here. I’ve add this issue more than once and that’s annoying. Let’s talk about this 😃
call
$container->resolveEnvPlaceholders()
on the $config array in your DI extension, this meaning you take responsibility for dealing with env varsHaving info about unused envs sound reasonable but this error also happens, as explained in #22561, by just overriding some configs in test env - which is very annoying and was a BC break for me (but happened only in test env for me, but could happen if someone had envs used in dev and then overwritten configs for prod).
fixed in #24009
@nicolas-grekas … sorry if my message in the #22726 sounded harsh and I even didn’t know if the solution I proposed on this PR would be a good one. My primary intention there was to bring this discussion up, because nobody (member or owner) answered to the issue I opened (#22561).
I’d read the original discussion (#19681) before I’ve even opened that issue to understand what I would be doing wrong. Actually, I didn’t understand everything there because both I don’t really know how Symfony works under the hood and the thread is too long. In this way, for me (as a final user), the exception thrown seems to be “crazy”. I also saw the PR #22976 that is an improvement, because it helps us to understand what we did “wrong”.
Anyway, my situation here now is: we are trying to deliver our application using docker containers and all of the configuration is made through environments variables. That helps us both for Continuous Integration and for easy and fast Deployments. Now, we can deploy a complete new environment using only one command with a new set of env variables that are sent on containers startup. Given the context, it’s completely normal that some environments variable is overridden sometimes.
With that exception, Symfony DI guarantees that every environment variable used at least once on at least one configuration file is being using on the resulted cache file. I have two concerns:
I apologize if “crazy” sounded too harsh 😞