diff --git a/src/main/scala/io.circe.config/parser.scala b/src/main/scala/io.circe.config/parser.scala index 7b25af0..e5cefd5 100644 --- a/src/main/scala/io.circe.config/parser.scala +++ b/src/main/scala/io.circe.config/parser.scala @@ -97,11 +97,13 @@ object parser extends Parser { .catchNonFatal { convertValueUnsafe { val config = parseConfig - path.fold(config) { - path => - if (config.hasPath(path)) config.getConfig(path) + path match { + case Some(path) => + if (config.hasPath(path)) config.getValue(path) else throw new ParsingFailure("Path not found in config", new ConfigException.Missing(path)) - }.root + case _ => + config.root + } } } .leftMap(error => ParsingFailure(error.getMessage, error)) diff --git a/src/test/scala/io.circe.config/CirceConfigSpec.scala b/src/test/scala/io.circe.config/CirceConfigSpec.scala index b782df9..92db78e 100644 --- a/src/test/scala/io.circe.config/CirceConfigSpec.scala +++ b/src/test/scala/io.circe.config/CirceConfigSpec.scala @@ -65,6 +65,10 @@ class CirceConfigSpec extends AnyFlatSpec with Matchers { parser.decode[AppSettings]().fold(fail(_), _ should equal (DecodedAppSettings)) } + it should "parse and decode config value from default typesafe config resolution with path" in { + parser.decodePath[Double]("http.version").fold(fail(_), _ should equal (DecodedAppSettings.http.version)) + } + it should "parse and decode config from default typesafe config resolution via ApplicativeError" in { parser.decodeF[IO, AppSettings]().unsafeRunSync() should equal (DecodedAppSettings) }