diff --git a/build.sbt b/build.sbt index 38ad30fcb..30948ab9d 100644 --- a/build.sbt +++ b/build.sbt @@ -14,7 +14,7 @@ val catsVersion = "1.0.1" val jsonpathVersion = "2.4.0" val macroCompatVersion = "1.1.1" val macroParadiseVersion = "2.1.1" -val pureconfigVersion = "0.8.0" +val pureconfigVersion = "0.9.0" val shapelessVersion = "2.3.3" val scalaCheckVersion = "1.13.5" val scalaXmlVersion = "1.0.6" diff --git a/modules/pureconfig/jvm/src/main/scala/eu/timepit/refined/pureconfig/package.scala b/modules/pureconfig/jvm/src/main/scala/eu/timepit/refined/pureconfig/package.scala index 5c2c4f7c6..28feb79f3 100644 --- a/modules/pureconfig/jvm/src/main/scala/eu/timepit/refined/pureconfig/package.scala +++ b/modules/pureconfig/jvm/src/main/scala/eu/timepit/refined/pureconfig/package.scala @@ -1,7 +1,7 @@ package eu.timepit.refined -import _root_.pureconfig.ConfigConvert -import _root_.pureconfig.error.{CannotConvert, ConfigReaderFailures, ConfigValueLocation} +import _root_.pureconfig.{ConfigConvert, ConfigCursor} +import _root_.pureconfig.error.{CannotConvert, ConfigReaderFailures, ConvertFailure} import com.typesafe.config.ConfigValue import eu.timepit.refined.api.{RefType, Validate} import scala.reflect.runtime.universe.WeakTypeTag @@ -14,19 +14,20 @@ package object pureconfig { validate: Validate[T, P], typeTag: WeakTypeTag[F[T, P]] ): ConfigConvert[F[T, P]] = new ConfigConvert[F[T, P]] { - override def from(config: ConfigValue): Either[ConfigReaderFailures, F[T, P]] = - configConvert.from(config) match { + override def from(cur: ConfigCursor): Either[ConfigReaderFailures, F[T, P]] = + configConvert.from(cur) match { case Right(t) => refType.refine[P](t) match { case Left(because) => Left( ConfigReaderFailures( - CannotConvert( - value = config.render(), - toType = typeTag.tpe.toString, - because = because, - location = ConfigValueLocation(config), - path = "" + ConvertFailure( + reason = CannotConvert( + value = cur.value.render(), + toType = typeTag.tpe.toString, + because = because + ), + cur = cur ))) case Right(refined) => diff --git a/modules/pureconfig/jvm/src/test/scala/eu/timepit/refined/pureconfig/RefTypeConfigConvertSpec.scala b/modules/pureconfig/jvm/src/test/scala/eu/timepit/refined/pureconfig/RefTypeConfigConvertSpec.scala index 0b8dba30c..c4be38ee4 100644 --- a/modules/pureconfig/jvm/src/test/scala/eu/timepit/refined/pureconfig/RefTypeConfigConvertSpec.scala +++ b/modules/pureconfig/jvm/src/test/scala/eu/timepit/refined/pureconfig/RefTypeConfigConvertSpec.scala @@ -7,7 +7,7 @@ import eu.timepit.refined.numeric.Positive import org.scalacheck.Prop._ import org.scalacheck.Properties import pureconfig._ -import pureconfig.error.{CannotConvert, ConfigReaderFailures} +import pureconfig.error.{CannotConvert, ConfigReaderFailures, ConvertFailure} class RefTypeConfigConvertSpec extends Properties("RefTypeConfigConvert") { @@ -22,10 +22,12 @@ class RefTypeConfigConvertSpec extends Properties("RefTypeConfigConvert") { property("load failure (predicate)") = secure { loadConfigWithValue("0") =? Left( - ConfigReaderFailures(CannotConvert( - value = "0", - toType = "eu.timepit.refined.api.Refined[Int,eu.timepit.refined.numeric.Greater[shapeless.nat._0]]", - because = "Predicate failed: (0 > 0).", + ConfigReaderFailures(ConvertFailure( + reason = CannotConvert( + value = "0", + toType = "eu.timepit.refined.api.Refined[Int,eu.timepit.refined.numeric.Greater[shapeless.nat._0]]", + because = "Predicate failed: (0 > 0)." + ), location = None, path = "value" ))) @@ -35,10 +37,12 @@ class RefTypeConfigConvertSpec extends Properties("RefTypeConfigConvert") { loadConfigWithValue("abc") =? Left( ConfigReaderFailures( - CannotConvert( - value = "abc", - toType = "Int", - because = "java.lang.NumberFormatException: For input string: \"abc\"", + ConvertFailure( + reason = CannotConvert( + value = "abc", + toType = "Int", + because = "java.lang.NumberFormatException: For input string: \"abc\"" + ), location = None, path = "value" )))