diff --git a/src/outpace/config.clj b/src/outpace/config.clj index 02ec7a5..c5e5070 100644 --- a/src/outpace/config.clj +++ b/src/outpace/config.clj @@ -175,13 +175,20 @@ "Finds and loads config." [] (if-let [source (find-config-source)] - (read-config source) + (with-meta (read-config source) :source source) {})) (def config "The delayed map of explicit configuration values." (delay (load-config))) +(defn config-source + "Returns the source of config as string or nil if no source was + found." + [] + (when-let [source (:source (meta @config))] + (str source))) + (defn present? "Returns true if a configuration entry exists for the qname and, if an Optional value, the value is provided." @@ -272,7 +279,10 @@ (if (present? qname#) (alter-var-root var# (constantly (lookup qname#))) (when (and (-> var# meta :required) (not generating?)) - (throw (Exception. (str "Missing required value for config var: " qname#))))) + (let [message# (if-let [source# (config-source)] + (str "Config var " qname# " must define a default or be specified in " source#) + (str "Config var " qname# " must define a default when there is no config source"))] + (throw (Exception. message#))))) (when-let [validate# (and (bound? var#) (-> var# meta :validate))] (validate @var# qname# validate#))) var#)) diff --git a/src/outpace/config/bootstrap.clj b/src/outpace/config/bootstrap.clj index 87124bc..32464e9 100644 --- a/src/outpace/config/bootstrap.clj +++ b/src/outpace/config/bootstrap.clj @@ -22,4 +22,5 @@ (io/resource res) (or (System/getProperty "config.edn") (when (.exists (io/file "config.edn")) - "config.edn"))))) + "config.edn"))) + (println "WARNING: no config source could be found."))) diff --git a/test/outpace/config_test.clj b/test/outpace/config_test.clj index 4a81cef..4802bee 100644 --- a/test/outpace/config_test.clj +++ b/test/outpace/config_test.clj @@ -444,3 +444,9 @@ (is (not (c/provided? #{(extractable "bar" false)}))) (is (not (c/provided? (list (extractable "bar" false))))) (is (not (c/provided? [(extractable "bar" false)]))))) + +(deftest config-source-test + (let [source "config.clj" + config (delay (with-meta {} {:source source}))] + (with-redefs [c/config config] + (is (= source (c/config-source))))))