lightbend / config

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

"include required()" is not working #595

Open fluency03 opened 6 years ago

fluency03 commented 6 years ago

I am having problem with using the keyword required for including another file.

This is NOT working:

include required(file("/path/application-secrets.conf"))

I got:

org.apache.flink.client.program.ProgramInvocationException: The main method caused an error.
        at org.apache.flink.client.program.PackagedProgram.callMainMethod(PackagedProgram.java:546)
        at org.apache.flink.client.program.PackagedProgram.invokeInteractiveModeForExecution(PackagedProgram.java:421)
        at org.apache.flink.client.program.ClusterClient.run(ClusterClient.java:426)
        at org.apache.flink.client.cli.CliFrontend.executeProgram(CliFrontend.java:804)
        at org.apache.flink.client.cli.CliFrontend.runProgram(CliFrontend.java:280)
        at org.apache.flink.client.cli.CliFrontend.run(CliFrontend.java:215)
        at org.apache.flink.client.cli.CliFrontend.parseParameters(CliFrontend.java:1044)
        at org.apache.flink.client.cli.CliFrontend.lambda$main$11(CliFrontend.java:1120)
        at org.apache.flink.runtime.security.NoOpSecurityContext.runSecured(NoOpSecurityContext.java:30)
        at org.apache.flink.client.cli.CliFrontend.main(CliFrontend.java:1120)
Caused by: com.typesafe.config.ConfigException$Parse: /var/opt/flink/jobs/clickstream/application-alerting.conf: 4: expecting include parameter to be quoted filename, file(), classpath(), or url(). No spaces are allowed before the open paren. Not expecting: 'required(file('
        at com.typesafe.config.impl.ConfigDocumentParser$ParseContext.parseError(ConfigDocumentParser.java:201)
        at com.typesafe.config.impl.ConfigDocumentParser$ParseContext.parseError(ConfigDocumentParser.java:197)
        at com.typesafe.config.impl.ConfigDocumentParser$ParseContext.parseInclude(ConfigDocumentParser.java:330)
        at com.typesafe.config.impl.ConfigDocumentParser$ParseContext.parseObject(ConfigDocumentParser.java:392)
        at com.typesafe.config.impl.ConfigDocumentParser$ParseContext.parse(ConfigDocumentParser.java:595)
        at com.typesafe.config.impl.ConfigDocumentParser.parse(ConfigDocumentParser.java:14)
        at com.typesafe.config.impl.Parseable.rawParseValue(Parseable.java:260)
        at com.typesafe.config.impl.Parseable.rawParseValue(Parseable.java:248)
        at com.typesafe.config.impl.Parseable.parseValue(Parseable.java:180)
        at com.typesafe.config.impl.Parseable.parseValue(Parseable.java:174)
        at com.typesafe.config.impl.Parseable.parse(Parseable.java:299)
        at com.typesafe.config.ConfigFactory.parseFile(ConfigFactory.java:734)
        at com.typesafe.config.ConfigFactory.parseFile(ConfigFactory.java:748)
        at com.ing.cybrct.flink.config.Configs$.apply(Configs.scala:91)
        at com.ing.cybrct.flink.package$.setup(package.scala:63)
        at com.ing.cybrct.flink.clickstream.alerting.AlertingByRules$.main(AlertingByRules.scala:24)
        at com.ing.cybrct.flink.clickstream.alerting.AlertingByRules.main(AlertingByRules.scala)
        at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
        at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:62)
        at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
        at java.lang.reflect.Method.invoke(Method.java:498)
        at org.apache.flink.client.program.PackagedProgram.callMainMethod(PackagedProgram.java:529)
        ... 9 more

This is working:

include file("/path/application-secrets.conf")
eshu commented 5 years ago

Seems like it happens when application tries to load file from the same directory where it has been run without any path mention (I omitted insignificant lines):

~/workspace$ cat <<END >basic.conf
> property: 5
> END
~/workspace$ cat <<END >envelope.conf
> envelope {
>   include required("basic")
> }
> END
~/workspace$ amm
...
@ import $ivy.`com.typesafe:config:1.3.4` 
import $ivy.$                          
@ com.typesafe.config.ConfigFactory.parseFile(new java.io.File("envelope.conf")) 
com.typesafe.config.ConfigException$IO: basic: basic.conf: java.io.FileNotFoundException: include was not found: 'basic.conf', basic.json: java.io.FileNotFoundException: include was not found: 'basic.json', basic.properties: java.io.FileNotFoundException: include was not found: 'basic.properties'
...
@ com.typesafe.config.ConfigFactory.parseFile(new java.io.File(sys.env("PWD") + "/envelope.conf")) 
res6: com.typesafe.config.Config = Config(SimpleConfigObject({"envelope":{"property":5}}))

@ com.typesafe.config.ConfigFactory.parseFile(new java.io.File("./envelope.conf")) 
res7: com.typesafe.config.Config = Config(SimpleConfigObject({"envelope":{"property":5}}))

@ Bye!
~/workspace$ cd ..
~$ amm
...
@ import $ivy.`com.typesafe:config:1.3.4` 
import $ivy.$                          

@ com.typesafe.config.ConfigFactory.parseFile(new java.io.File("workspace/envelope.conf")) 
res1: com.typesafe.config.Config = Config(SimpleConfigObject({"envelope":{"property":5}}))

So there is a workaround: just add "./" or another path to argument.

But definitely it is a bug...

jomach commented 1 year ago

same issue !

alfonsonishikawa commented 1 year ago

@eshu Did you try include required("basic.conf")?

jomach commented 1 year ago

@eshu Did you try include required("basic.conf")? I tried that ! Did not work