ConfigReader.map is broken for readers with ReadsMissingKeys
See original GitHub issueval Right(cfg) = ConfigFactoryWrapper.parseString("")
val reader1 = ConfigReader.forProduct1("foo")(identity[Option[Int]])(
ConfigReader[Option[Int]]
)
reader1.from(cfg.root) // Right
val reader2 = ConfigReader.forProduct1("foo")(identity[Option[Int]])(
ConfigReader[Option[Int]].map(identity)
)
reader2.from(cfg.root) // Left
That is, .map(identity)
, surprisingly, results in a ConfigReader
with a different behavior, breaking the functor law!
There are two ways to fix this. First, we can crawl through our codebase, and make sure all the ConfigReader
combinators preserve ReadsMissingKeys
. Alternatively, we can somehow change the ConfigReader
abstraction to eliminate ReadsMissingKeys
altogether. We can look at what Circe does here.
Issue Analytics
- State:
- Created 3 years ago
- Reactions:2
- Comments:9 (9 by maintainers)
Top Results From Across the Web
pureconfig - Bountysource
ConfigReader.map is broken for readers with ReadsMissingKeys $ 0 ... Created 1 year ago in pureconfig/pureconfig with 4 comments. Consider: val Right(cfg) = ......
Read more >Case Classes - PureConfig
How do keys in config objects map to field names of the case class? ... For ConfigReader s extending ReadsMissingKeys , a missing...
Read more >Pureconfig read config as properties map - Stack Overflow
Pureconfig only takes these nested configs and maps them into case classes. ... implicit val strMapReader: ConfigReader[Map[String, ...
Read more >PureConfig pureconfig Issues - Giters
Case class instance unexpectedly shared across map entries. Updated 5 months ago 3 ... ConfigReader.map is broken for readers with ReadsMissingKeys.
Read more >Top Related Medium Post
No results found
Top Related StackOverflow Question
No results found
Troubleshoot Live Code
Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start FreeTop Related Reddit Thread
No results found
Top Related Hackernoon Post
No results found
Top Related Tweet
No results found
Top Related Dev.to Post
No results found
Top Related Hashnode Post
No results found
Top GitHub Comments
Your right, you can just use the
forProduct
and help the type inference, I just implemented like thisThe
.copy
is unfortunately privateI just came across this issue in a more disguised form. I’m posting it here for posteriority since it also took me a while to figure it out.
Consider the following:
However, if we happen to introduce an extra import:
The reason for this is that we have an implicit
fromReaderAndWriter
inConfigConvert
that produces aConfigConvert
from aConfigReader
and aConfigWriter
. When this implicit gets a higher priority, it will be used to produce aConfigConvert[Option[Int]]
, which is also aConfigReader[Option[Int]]
, and will therefore be used when deriving aConfigReader[Foo]
. However, theConfigConvert[Option[Int]]
won’t retain theReadsMissingKeys
type and will therefore be used to create aConfigReader[Foo]
with a different behavior from the default.