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

Integrate with clojure.spec #33

Open
malcolmsparks opened this issue Nov 30, 2016 · 1 comment
Open

Integrate with clojure.spec #33

malcolmsparks opened this issue Nov 30, 2016 · 1 comment

Comments

@malcolmsparks
Copy link
Contributor

See this paper for why: https://blog.acolyer.org/2016/11/29/early-detection-of-configuration-errors-to-reduce-failure-damage/

@bsima
Copy link

bsima commented Mar 9, 2017

Integration can be as simple as:

(def config
  (let [cfg  (aero/read-config (io/resource "config.edn"))]
    (if-not (spec/valid? ::conf-spec/config cfg)
      (throw (Exception. (spec/explain-str ::conf-spec/config cfg)))
      ;; if config is valid, return the map
      cfg)))

That's actually what I use in my codebase, albeit slightly modified (I removed mount's defstate and some custom error handling stuff, but the gist is the same).

::conf-spec/config is another namespace that is dedicated to specing my config map. It works really well for me.

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

No branches or pull requests

2 participants