Sebastian Schuberth
03/25/2025, 8:24 PMloadConfig()
fails if there is nothing to load from any configured property source. I'd like to fall back to some default configuration on that kind of "failure". However, I still want to capture "real" failures, like syntax errors in configuration files. What's the correct way to distinguish "no config available" from "config broken" in Hoplite?Chris Lee
03/25/2025, 11:03 PMSebastian Schuberth
03/26/2025, 6:56 AMSebastian Schuberth
03/26/2025, 6:57 AMConfigFailure.UndefinedTree
. But that does not work anymore as soon as I add .addEnvironmentSource()
. Then an empty configuration suddenly causes ConfigFailure.MissingConfigValue
.dave08
03/26/2025, 11:33 AMSebastian Schuberth
03/26/2025, 11:35 AMdave08
03/26/2025, 11:40 AMConfigLoaderBuilder.default().apply {
addDecoder(IntRangeDecoder())
addEnvironmentSource()
val envs = System.getenv("MICRONAUT_ENVIRONMENTS")?.split(',') ?: emptyList()
envs.reversed().forEach {
addResourceSource("/application-$it.yaml", optional = true)
}
addResourceSource("/application.yaml")
}.build().loadConfigOrThrow<Settings>()
dave08
03/26/2025, 11:41 AMdave08
03/26/2025, 11:41 AMdave08
03/26/2025, 11:43 AMSebastian Schuberth
03/26/2025, 11:48 AMdave08
03/26/2025, 11:51 AMdave08
03/26/2025, 11:53 AMoptional
parameter in addResourceSource
... then if that file doesn't exist, it won't crash.rocketraman
03/28/2025, 2:30 PMIt crashes even if you provide default values in all your configs' data classes?This particular case should be fixed with https://github.com/sksamuel/hoplite/pull/486.