wrench
wrench copied to clipboard
EDN coercion is broken
Would this explain the following failing ?
(ns app.env
(:require [wrench.core :as cfg]
[clojure.spec.alpha :as s]))
(s/def ::env #{"DEV" "PROD"})
(cfg/def ENV {:name "MYAPP_ENV"
:default "PROD"
:spec ::env})
dev-config.edn:
{"MYAPP_ENV" "DEV"}
From a repl
> (cfg/reset! :env (cfg/from-file "dev-config.edn"))
> (cfg/validate-and-print)
Failed to load config:
- configuration #'app.env/ENV present, but does not conform spec: nil
@jwdevantier hallo! sorry for the late reply.
The issue you are facing is related to the fact that when Clojure reads EDN from a sting, it would interpret single string as a symbol. So if you change your spec to this
(s/def ::env #{'DEV 'PROD})
Then the validation would pass. I understand that it is not intuitive at all :) and it would be nice to have a way of limiting the value with a spec while still having them as strings. And it also does not print the actual spec.
Let me check what could be done about it and get back