wrench icon indicating copy to clipboard operation
wrench copied to clipboard

EDN coercion is broken

Open Otann opened this issue 4 years ago • 2 comments

Otann avatar Dec 15 '20 16:12 Otann

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 avatar Feb 14 '21 19:02 jwdevantier

@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

Otann avatar Feb 23 '21 20:02 Otann