question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

Derivation is failing to resolve a custom ConfigConvert materializer

See original GitHub issue

Context: I’m working on an integration of coulomb with pureconfig.

I have a generator (see this pull-req) for ConfigConvert that appears to work well in isolation (it will instantiate implicitly when using to and from on a coulomb Quantity). However, when I try to declare a configuration case class that has Quantity members, the corresponding reader will not resolve implicitly, unless I explicitly declare ConfigConvert, in which case it will work. Here’s an example session, where you can see my first loadConfig fail, and then after I declare the two ConfigConvert values explicitly, it succeeds:

scala> import coulomb._, coulomb.si._, coulomb.time._, coulomb.info._, coulomb.typesafeconfig._, coulomb.parser._, com.typesafe.config._, coulomb.siprefix._, shapeless._, org.apache.avro._, org.apache.avro.generic._, org.apache.avro.file._, coulomb.avro._, coulomb.binprefix._, _root_.pureconfig._, _root_.pureconfig.generic.auto._, coulomb.pureconfig._

scala> implicit val qp = QuantityParser[Second :: Byte :: Hour :: Giga :: HNil]
qp: coulomb.parser.QuantityParser = coulomb.parser.QuantityParser@67b5409b

scala> case class QC(t: Quantity[Double, Second], m: Quantity[Double, Mega %* Byte])
defined class QC

scala> val conf = ConfigFactory.parseString("""{ "t": { "value": 1, "unit":"hour" }, "m": { "value": 1, "unit": "gigabyte" } }""") 
conf: com.typesafe.config.Config = Config(SimpleConfigObject({"m":{"unit":"gigabyte","value":1},"t":{"unit":"hour","value":1}}))

scala> val conf = ConfigFactory.parseString("""{ t: { value: 1, unit: "hour" }, m: { value: 1, unit: "gigabyte" } }""") 
conf: com.typesafe.config.Config = Config(SimpleConfigObject({"m":{"unit":"gigabyte","value":1},"t":{"unit":"hour","value":1}}))

scala> loadConfig[QC](conf)
                     ^
       error: Cannot find an implicit instance of pureconfig.ConfigReader[QC].
       If you are trying to read or write a case class or sealed trait consider using PureConfig's auto derivation by adding `import pureconfig.generic.auto._`

scala> implicit val ttt = implicitly[ConfigConvert[Quantity[Double, Second]]]
ttt: pureconfig.ConfigConvert[coulomb.Quantity[Double,coulomb.si.Second]] = coulomb.pureconfig.package$$anon$1@71f0008b

scala> implicit val ttt2 = implicitly[ConfigConvert[Quantity[Double, Mega %* Byte]]]
ttt2: pureconfig.ConfigConvert[coulomb.Quantity[Double,coulomb.siprefix.Mega %* coulomb.info.Byte]] = coulomb.pureconfig.package$$anon$1@721a582

scala> loadConfig[QC](conf)
res1: pureconfig.ConfigReader.Result[QC] = Right(QC(Quantity(3600.0),Quantity(1000.0)))

Issue Analytics

  • State:closed
  • Created 4 years ago
  • Comments:5 (5 by maintainers)

github_iconTop GitHub Comments

1reaction
erikerlandsoncommented, Jul 28, 2019

@ruippeixotog thanks! For fun, I tried compiling it as part of the test build. I dropped the following into my source:

object pctest {
  import coulomb._, coulomb.si._, coulomb.time._, coulomb.info._, coulomb.typesafeconfig._, coulomb.parser._, com.typesafe.config._, coulomb.siprefix._, shapeless._, coulomb.binprefix._, _root_.pureconfig._, _root_.pureconfig.generic.auto._, coulomb.pureconfig._

  implicit val qp = QuantityParser[Second :: Byte :: Hour :: Giga :: HNil]

  case class QC(t: Quantity[Double, Second], m: Quantity[Double, Mega %* Byte])

  val conf = ConfigFactory.parseString("""{ "t": { "value": 1, "unit":"hour" }, "m": { "value": 1, "unit": "gigabyte" } }""") 

  val qc = loadConfig[QC](conf)  // Now I compile!
}

When I do it that way, it compiles fine! That suggests it isn’t a bug in pureconfig, but maybe the REPL’s environment is not set up quite right to make the implicit tree resolve.

0reactions
ruippeixotogcommented, Jul 28, 2019

That’s great to hear! The Scala REPL is indeed very flaky, I’m glad it works in a normal environment.

Read more comments on GitHub >

github_iconTop Results From Across the Web

com.typesafe.config.ConfigValueFactory Scala Example
newSingleThreadScheduledExecutor() protected implicit val materializer: ... ConfigConvert, ConfigReader, ConfigWriter, Derivation } import pureconfig.error.
Read more >
Read Pure functional HTTP APIs in Scala | Leanpub
Why do I have a bad feeling about this? Well, maybe because a list may contain duplicate entries but the database will surely...
Read more >
Deploying Java EE Microservices on OpenShift
This was a nice way to test things locally. What was missing so far is to put this into production. Let's look what...
Read more >
[ddh-sys] apt-listchanges: changelogs for less
Fixed CVE-2010-0628: denial of service (assertion failure and daemon crash) via ... Clarify comments in suexec-custom's default config file.
Read more >
pureconfig - bytemeta
Failing UnexpectedValueForFieldCoproductHint. whoisvolos ... Derivation is failing to resolve a custom ConfigConvert materializer. nigredo-tori.
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found