immuconf icon indicating copy to clipboard operation
immuconf copied to clipboard

Allow attempts to load files that don't exist

Open MatthewDarling opened this issue 9 years ago • 3 comments

The config loading code for the application I work on looks roughly like this:

(->> ["resources/config.edn" "/special/prod/folder/config.edn" "/special/dev/folder/config.edn"]
     (map load-file-if-exists)
     (apply merge))

Rather than having different code for loading config in prod, we just load a file from a folder that will only exist in the prod environment. And there's a priority list so developers can override things locally.

I think, philosophically, this is very similar to immuconf. I'm hoping to switch because the tagged literals look great :) However, currently immuconf will throw an exception if one of the desired files doesn't exist.

So, this PR changes load-cfg-file so that files that don't exist are ignored. For our application, the resources/config.edn will always exist so that config will be used if no other files have been created.


One case that might need special handling is when all the desired files don't exist. In that case, the config is returned as an empty map... That's probably not desired behaviour, and I can imagine cases where that would break a user's application.

MatthewDarling avatar Mar 31 '16 15:03 MatthewDarling

This makes a lot of sense. I myself use the pattern in lambda-example.config in a popular recent blog post, A look at running Clojure on AWS Lambda, where the author applies this to loading files which may or may not be present:

(def config
  (apply 
    conf/load 
    (filter 
      (partial not= nil) 
      [(base-config) (s3-config) (local-config)])))

It would of course be great to incorporate this intent, which @MatthewDarling has done, into immuconf itself as proposed here.

russellwhitaker avatar Mar 31 '16 17:03 russellwhitaker

@levand would incorporating @MatthewDarling 's changes be made easier if I cherrypicked them into russellwhitaker/immuconf first and made the dual-target clj/cljs conversions there, then issue a follow-up PR?

russellwhitaker avatar Apr 06 '16 15:04 russellwhitaker

It would be really useful to be able to "mark" the files as required or not, similar to the default and override tags in the configs.

jgomo3 avatar Feb 07 '23 13:02 jgomo3