-
Notifications
You must be signed in to change notification settings - Fork 967
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
BugOrBrokenException when using optional overrides and resolveWith #332
Comments
I can't fix this right away (patches welcome), but for future reference: Here is a test case for the end of ConfigTest.scala:
Here is how it currently fails:
I think the problem is that we shouldn't be trying to do a replacement when the substitution we're resolving is not inside the resolve source. The right fix, I don't know without digging in. |
thanks for the report btw! |
I’ve taken a look at this. Is there a test that could be added to demonstrate why the exception is needed in this case? |
The reason I haven't fixed this of course is that I don't know offhand what the deal is ;-) Here's a quick scan but I could easily be wrong without digging in more. It looks like replaceWithinCurrentParent is only called here: What we're doing is that if we have some stuff that overrides some stuff but requires resolving substitutions, like To allow this replacement, we track ResolveSource.pathFromRoot so we can go up that path (to replace the leaf node, we replace its parent with a parent with the replacement node, then we recursively go up replacing each parent). The BugOrBroken is thrown when we aren't at the root, and we don't have a pathFromRoot, so we don't know our parent node. That means we can't do the replacement because we can't walk up the tree. I don't think we could add a test showing why this exception should be thrown because the point of it is to catch a believed-impossible situation. Clearly it isn't actually impossible. Look at In Note also the comment here: https://github.com/typesafehub/config/blob/master/config/src/main/java/com/typesafe/config/impl/ConfigDelayedMerge.java#L108 that's talking about resetParents() which is in fact a couple of lines below. But it's saying that after we replace a parent, on this line, we should be doing the equivalent of I'm not sure if it's possible for So if that's true, this only happens with We have to think about what should happen with My initial take then is that you're right, we could Might be nice to also add some more text to the |
Thanks for digging in to this, btw. |
Any update on that? Will be fixed? |
I can confirm that jln-ho's commit fixes this for us, with no noticeable different in functionality as far as I can tell. |
Do you think this issue will be resolved or a workaround is available? |
I am also interested on a fix / workaround |
Exception in thread "main" com.typesafe.config.ConfigException$BugOrBroken: replace in parent not possible The docs for resolveWith says: > Note that this method does NOT look in this instance for substitution values. Which means we can't refer to variabled in the same config. It also says If you want to do that, you could either merge this instance into your value source using Config.withFallback, or you could resolve multiple times with multiple sources (using setAllowUnresolved). I tried using withFallback, but the same error still occurred. This might be due to a bug in typesafe config: lightbend/config#332 This works around that by resolving multiple times as suggested in the javadoc.
Resolve failed with the following exception when using references: Exception in thread "main" com.typesafe.config.ConfigException$BugOrBroken: replace in parent not possible The docs for resolveWith says: > Note that this method does NOT look in this instance for substitution values. Which means we can't refer to variabled in the same config. It also says If you want to do that, you could either merge this instance into your value source using Config.withFallback, or you could resolve multiple times with multiple sources (using setAllowUnresolved). I tried using withFallback, but the same error still occurred. This might be due to a bug in typesafe config: lightbend/config#332 This works around that by resolving multiple times as suggested in the javadoc.
Resolve failed with the following exception when using references: Exception in thread "main" com.typesafe.config.ConfigException$BugOrBroken: replace in parent not possible The docs for resolveWith says: > Note that this method does NOT look in this instance for substitution values. Which means we can't refer to variabled in the same config. It also says: > If you want to do that, you could either merge this instance into > your value source using Config.withFallback, or you could resolve > multiple times with multiple sources (using setAllowUnresolved). I tried using withFallback, but the same error still occurred. This might be due to a bug in typesafe config: lightbend/config#332 This works around that by resolving multiple times as suggested in the javadoc.
I found the following workaround helped in my case, to resolve against system parameters: File confFile = new File("...");
Config config = ConfigFactory.parseFile(confFile);
Config system = ConfigFactory.systemProperties();
Config finale = config.withFallback(system).resolve(); In my case this made the following config work as I expect and fallback to explicit defaults as well as interpolate system properties if present:
|
eg. anything like this:
where you might like to (possibly) resolve
maybe.some.other.value
without polluting extraneous values (such as you might get with system properties) or doing some kind of janky whitelist. Works fine in 1.2.1, aside from that being the version that still doesn't have my other fix from a million years ago.The text was updated successfully, but these errors were encountered: