ludat / conferer

Configuration managment for haskell
https://conferer.ludat.io
Mozilla Public License 2.0
21 stars 4 forks source link

Forgetting a FromConfig / Generic instance compiles with runtime exception #96

Open vikrem opened 2 years ago

vikrem commented 2 years ago

With the following program on GHC 8.10.7, conferer 1.1.0.0:

data Foo = Foo { secret :: Text }

appMain :: IO ()
appMain = do
  cfg <- mkConfig' [] [fromFilePath "config.properties"]
  appConfig' <- fetchFromConfig @Foo "" cfg
  exitSuccess

This compiles and runs, without deriving Generic or FromConfig. The application crashes with an exception:

app-exe: Failed to get a 'Foo' from keys: ""

Setting a secret key in config.properties doesn't help and the application continues to crash in the same manner. Deliberately adding a blank instance of FromConfig, and deriving Generic fixes the problem, but there is no indication to do so.

ludat commented 2 years ago

Hi @vikrem,

Yes, that's kind of by design of conferer v1, there is an all encompassing instance FromConfig a so that means that if you try to get an instance from something that doesn't have a FromConfig instance it will pick the default one (which always fails no matter what)

I'm preparing a v2 release which will fix this, and trying to use fetchFromConfig with something that doesn't have a FromConfig instance will not compile.

It's still not ready though since I've been busy and the prototypes that I've build still don't sit right.

As soon as v2 is out I'll close this issue

vikrem commented 2 years ago

It looks like #87 removes that all encompassing instance. Is that to be cut into v2 and won't be in v1 then?

ludat commented 2 years ago

oh haha, I forgot I had that merged.

That's right, v2 will be quite a change, so I think it will need manual intervention from users so I probably won't backport it