Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Allow attempts to load files that don't exist #8

Open
wants to merge 3 commits into
base: master
Choose a base branch
from

Conversation

MatthewDarling
Copy link

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.

Matthew Darling added 3 commits March 31, 2016 11:17
Also clarify the behaviour when all requested files are missing, in case
it changes after PR discussion.
@russellwhitaker
Copy link

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
Copy link

@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?

@jgomo3
Copy link

jgomo3 commented Feb 7, 2023

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.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants