elixir-toniq / vapor

Runtime configuration system for Elixir

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

Specify types in our configuration instead of when fetched.

keathley opened this issue · comments

I've been thinking about this a bit and I think that we should consider requiring the types for a given value when we define the configuration instead of doing it on the fly each time. There are tradeoffs to this approach which I'll try to list here:

  • Specification at compile time allows us to stop an app from booting if the app is misconfigured. This is generally good because otherwise you end up with obscure errors that are much more difficult to track down.
  • Slims down the api for retrieving values. Otherwise this is going to be quite repetitive.
  • In the general case I don't think people need to choose between different types when they're fetching a value from the configuration.
  • This change would make it much much harder to change a configuration value once the app has already been booted.

Personally I think the benefits greatly outweigh the costs here but I may be missing something. Interested to see what y'all think.

It sounds interesting. Type assertions during startup could definitely be helpful. I also like the idea of slimming down the getter syntax :)

In regards of specifying the types: How would, for instance, Env.with_prefix("APP") be type notated?

I'm still trying to think through the api for this. I think part of the issue is that the specifications would have to be done per provider since each provider returns data in slightly different formats. I also don't know how this would work with something like the env providers with_prefix option. But perhaps its better to just be explicit over convenient in this case.