lightbend / config

configuration library for JVM languages using HOCON files
https://lightbend.github.io/config/
6.12k stars 968 forks source link

Substituting environment variables fails when merging objects #786

Closed yantonov closed 1 year ago

yantonov commented 1 year ago

From the first glance it's related to https://github.com/lightbend/config/issues/356 https://github.com/lightbend/config/issues/647 https://github.com/lightbend/config/issues/725

Here is an example of the config:

prod {
    catalog {
        aws-access-key-id = [ "1" ]
        aws-access-list-key-id = [ "1" ]
    }
}

dev = ${prod} {
    catalog {
        # doesn't work
        aws-access-key-id = "2"
        aws-access-key-id = ${?AWS_ACCESS_KEY_ID}
        # but this one works
        aws-access-list-key-id = [ "2", ${?AWS_ACCESS_KEY_ID} ]
    }
}

Error:

Stack:

com.typesafe.config.ConfigException$BugOrBroken: SimpleConfigObject.replaceChild did not find SimpleConfigObjec
    at com.typesafe.config.impl.SimpleConfigObject.replaceChild(SimpleConfigObject.java:216)
    at com.typesafe.config.impl.SimpleConfigObject.replaceChild(SimpleConfigObject.java:26)
    at com.typesafe.config.impl.ResolveSource.replace(ResolveSource.java:192)
    at com.typesafe.config.impl.ResolveSource.replace(ResolveSource.java:193)
    at com.typesafe.config.impl.ResolveSource.replaceCurrentParent(ResolveSource.java:209)
    at com.typesafe.config.impl.ResolveSource.replaceWithinCurrentParent(ResolveSource.java:240)
    at com.typesafe.config.impl.ConfigDelayedMerge.resolveSubstitutions(ConfigDelayedMerge.java:110)
    at com.typesafe.config.impl.ConfigDelayedMerge.resolveSubstitutions(ConfigDelayedMerge.java:59)
    at com.typesafe.config.impl.ResolveContext.realResolve(ResolveContext.java:183)
    at com.typesafe.config.impl.ResolveContext.resolve(ResolveContext.java:146)
    at com.typesafe.config.impl.SimpleConfigObject$ResolveModifier.modifyChildMayThrow(SimpleConfigObject.java:380)
    at com.typesafe.config.impl.SimpleConfigObject.modifyMayThrow(SimpleConfigObject.java:313)
    at com.typesafe.config.impl.SimpleConfigObject.resolveSubstitutions(SimpleConfigObject.java:399)
    at com.typesafe.config.impl.ResolveContext.realResolve(ResolveContext.java:183)
    at com.typesafe.config.impl.ResolveContext.resolve(ResolveContext.java:146)
    at com.typesafe.config.impl.SimpleConfigObject$ResolveModifier.modifyChildMayThrow(SimpleConfigObject.java:380)
    at com.typesafe.config.impl.SimpleConfigObject.modifyMayThrow(SimpleConfigObject.java:313)
    at com.typesafe.config.impl.SimpleConfigObject.resolveSubstitutions(SimpleConfigObject.java:399)
    at com.typesafe.config.impl.ResolveContext.realResolve(ResolveContext.java:183)
    at com.typesafe.config.impl.ResolveContext.resolve(ResolveContext.java:146)
    at com.typesafe.config.impl.ConfigConcatenation.resolveSubstitutions(ConfigConcatenation.java:205)
    at com.typesafe.config.impl.ResolveContext.realResolve(ResolveContext.java:183)
    at com.typesafe.config.impl.ResolveContext.resolve(ResolveContext.java:146)
    at com.typesafe.config.impl.SimpleConfigObject$ResolveModifier.modifyChildMayThrow(SimpleConfigObject.java:380)
    at com.typesafe.config.impl.SimpleConfigObject.modifyMayThrow(SimpleConfigObject.java:313)
    at com.typesafe.config.impl.SimpleConfigObject.resolveSubstitutions(SimpleConfigObject.java:399)
    at com.typesafe.config.impl.ResolveContext.realResolve(ResolveContext.java:183)
    at com.typesafe.config.impl.ResolveContext.resolve(ResolveContext.java:146)
    at com.typesafe.config.impl.ResolveContext.resolve(ResolveContext.java:235)
    at com.typesafe.config.impl.SimpleConfig.resolveWith(SimpleConfig.java:79)
    at com.typesafe.config.impl.SimpleConfig.resolve(SimpleConfig.java:69)
    at com.typesafe.config.impl.SimpleConfig.resolve(SimpleConfig.java:42)
    at com.typesafe.config.ConfigFactory.load(ConfigFactory.java:219)
    at com.typesafe.config.ConfigFactory.load(ConfigFactory.java:119)
    at com.typesafe.config.ConfigFactory.load(ConfigFactory.java:79)
    at com.typesafe.config.impl.ConfigTest.overrideUsingEnvVarAtChildLevel(ConfigTest.scala:1367)
lightbend-cla-validator commented 1 year ago

Hi @yantonov,

Thank you for your contribution! We really value the time you've taken to put this together.

Before we proceed with reviewing this pull request, please sign the Lightbend Contributors License Agreement:

https://www.lightbend.com/contribute/cla

ennru commented 1 year ago

We do not intend to extend the functionality of "Typesafe Config" further. See https://github.com/lightbend/config#maintained-by