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

Quarkus Mail + Env Variable + 0.23.1 #4245

Closed
lbernardomaia opened this issue Sep 27, 2019 · 8 comments
Closed

Quarkus Mail + Env Variable + 0.23.1 #4245

lbernardomaia opened this issue Sep 27, 2019 · 8 comments
Labels
kind/bug Something isn't working triage/invalid This doesn't seem right

Comments

@lbernardomaia
Copy link

Hi,

There is an issue that I'm facing after upgrade to 0.23.1 version, I don't face the issue when using 0.22.0.

Basically, if I have the code below, and the env variables are empty i.e MAIL_USER=, an error is thrown when using the native image.

application.properties

quarkus.mailer.username=${MAIL_USER}
quarkus.mailer.password=${MAIL_PASSWORD}

log:

java.util.NoSuchElementException: Property MAIL_USER not found
        at io.smallrye.config.SmallRyeConfig.propertyNotFound(SmallRyeConfig.java:221)
        at io.smallrye.config.SmallRyeConfig.getValue(SmallRyeConfig.java:112)
        at io.quarkus.runtime.configuration.ConfigExpander.accept(ConfigExpander.java:55)
        at io.quarkus.runtime.configuration.ConfigExpander.accept(ConfigExpander.java:15)
        at org.wildfly.common.expression.ExpressionNode.emit(ExpressionNode.java:42)
        at org.wildfly.common.expression.Expression.evaluateException(Expression.java:75)
        at org.wildfly.common.expression.Expression.evaluate(Expression.java:89)
        at io.quarkus.runtime.configuration.ExpandingConfigSource.expandValue(ExpandingConfigSource.java:76)
        at io.quarkus.runtime.configuration.ExpandingConfigSource.expand(ExpandingConfigSource.java:48)
        at io.quarkus.runtime.configuration.ExpandingConfigSource.getValue(ExpandingConfigSource.java:44)
        at io.quarkus.runtime.configuration.DeploymentProfileConfigSource.getValue(DeploymentProfileConfigSource.java:57)
        at io.smallrye.config.SmallRyeConfig.getOptionalValue(SmallRyeConfig.java:136)
        at io.smallrye.config.SmallRyeConfig.getOptionalValue(SmallRyeConfig.java:131)
        at io.quarkus.runtime.configuration.ConfigUtils.getOptionalValue(ConfigUtils.java:92)
        at io.quarkus.runtime.generated.RunTimeConfig.parseKey_mailer_username(RunTimeConfig.zig:26910)
        at io.quarkus.runtime.generated.RunTimeConfig.parseKey_mailer(RunTimeConfig.zig:11247)
        at io.quarkus.runtime.generated.RunTimeConfig.parseKey(RunTimeConfig.zig:14679)
        at io.quarkus.runtime.generated.RunTimeConfig.getRunTimeConfiguration(RunTimeConfig.zig:32470)
        at io.quarkus.runner.ApplicationImpl1.doStart(ApplicationImpl1.zig:125)
        at io.quarkus.runtime.Application.start(Application.java:93)
        at io.quarkus.runtime.Application.run(Application.java:213)
        at io.quarkus.runner.GeneratedMain.main(GeneratedMain.zig:34)
Exception in thread "main" java.lang.RuntimeException: Failed to start quarkus
        at io.quarkus.runner.ApplicationImpl1.doStart(ApplicationImpl1.zig:259)
        at io.quarkus.runtime.Application.start(Application.java:93)
        at io.quarkus.runtime.Application.run(Application.java:213)
        at io.quarkus.runner.GeneratedMain.main(GeneratedMain.zig:34)
Caused by: java.util.NoSuchElementException: Property MAIL_USER not found
        at io.smallrye.config.SmallRyeConfig.propertyNotFound(SmallRyeConfig.java:221)
        at io.smallrye.config.SmallRyeConfig.getValue(SmallRyeConfig.java:112)
        at io.quarkus.runtime.configuration.ConfigExpander.accept(ConfigExpander.java:55)
        at io.quarkus.runtime.configuration.ConfigExpander.accept(ConfigExpander.java:15)
        at org.wildfly.common.expression.ExpressionNode.emit(ExpressionNode.java:42)
        at org.wildfly.common.expression.Expression.evaluateException(Expression.java:75)
        at org.wildfly.common.expression.Expression.evaluate(Expression.java:89)
        at io.quarkus.runtime.configuration.ExpandingConfigSource.expandValue(ExpandingConfigSource.java:76)
        at io.quarkus.runtime.configuration.ExpandingConfigSource.expand(ExpandingConfigSource.java:48)
        at io.quarkus.runtime.configuration.ExpandingConfigSource.getValue(ExpandingConfigSource.java:44)
        at io.quarkus.runtime.configuration.DeploymentProfileConfigSource.getValue(DeploymentProfileConfigSource.java:57)
        at io.smallrye.config.SmallRyeConfig.getOptionalValue(SmallRyeConfig.java:136)
        at io.smallrye.config.SmallRyeConfig.getOptionalValue(SmallRyeConfig.java:131)
        at io.quarkus.runtime.configuration.ConfigUtils.getOptionalValue(ConfigUtils.java:92)
        at io.quarkus.runtime.generated.RunTimeConfig.parseKey_mailer_username(RunTimeConfig.zig:26910)
        at io.quarkus.runtime.generated.RunTimeConfig.parseKey_mailer(RunTimeConfig.zig:11247)
        at io.quarkus.runtime.generated.RunTimeConfig.parseKey(RunTimeConfig.zig:14679)
        at io.quarkus.runtime.generated.RunTimeConfig.getRunTimeConfiguration(RunTimeConfig.zig:32470)
        at io.quarkus.runner.ApplicationImpl1.doStart(ApplicationImpl1.zig:125)
        ... 3 more
@lbernardomaia lbernardomaia added the kind/bug Something isn't working label Sep 27, 2019
@machi1990
Copy link
Member

related to #4123? @dmlloyd @gsmet

@dmlloyd
Copy link
Member

dmlloyd commented Sep 27, 2019

No, it's a new problem, but working as designed: by specifying the environment variable as empty (rather than undefining it), you're explicitly saying that you want the value to be empty, which will cause a failure. Since you're expanding the property with no default, you're also causing the property to be undefined as well.

So, first you need to change your config like this:

quarkus.mailer.username=${MAIL_USER:}
quarkus.mailer.password=${MAIL_PASSWORD:}

This says "if the property is empty or missing, expand to an empty string".

Now, there is a good argument to say that when expanding a variable, empty values should expand into empty strings implicitly. However the problem is that the config infrastructure deliberately does not attempt to make a distinction between explicitly empty or empty-because-it-is-missing. Thus if we were to make such a change, it would mean that it would be impossible to cause a failure when a referenced property is not present.

If this whole thing just stinks to you, another approach would be to remove these two properties and environment variables from your configuration, and instead use the "QUARKUS_MAILER_USERNAME" and "QUARKUS_MAILER_PASSWORD" environment variables directly.

@machi1990
Copy link
Member

Thanks @dmlloyd for chiming in with a good explanation.

"QUARKUS_MAILER_USERNAME" and "QUARKUS_MAILER_PASSWORD" environment variables directly.

Indeed, this is a good alternative solution since mailer configurations can be overridden at runtime.

@geoand
Copy link
Contributor

geoand commented Sep 28, 2019

So should this be closed as invalid (working as expected)?

@dmlloyd
Copy link
Member

dmlloyd commented Sep 28, 2019

Sure, unless someone has a good argument that the current behavior is wrong.

@cescoffier
Copy link
Member

Agreed, I made the mailer this way actually. username and password are runtime as IMHO it's a runtime thing.

@cescoffier cescoffier added the triage/invalid This doesn't seem right label Sep 30, 2019
@cescoffier
Copy link
Member

Please reopen if you disagree with the invalidity.

@lbernardomaia
Copy link
Author

Agree, thanks for the explanation @dmlloyd !

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
kind/bug Something isn't working triage/invalid This doesn't seem right
Projects
None yet
Development

No branches or pull requests

5 participants