From 9328e3cb9e792eb417099b6954a5e933b7af7977 Mon Sep 17 00:00:00 2001 From: Joel Holdbrooks Date: Fri, 29 Mar 2019 17:56:37 -0700 Subject: [PATCH 1/6] Print a warning when config cannot be found --- src/outpace/config/bootstrap.clj | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) 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."))) From 75873c62bfe6a2a03028657efec57f4a017e32e6 Mon Sep 17 00:00:00 2001 From: Joel Holdbrooks Date: Mon, 1 Apr 2019 13:33:39 -0700 Subject: [PATCH 2/6] Annotate read config with :source meta, clearer missing config error messsage --- src/outpace/config.clj | 19 ++++++++++++------- 1 file changed, 12 insertions(+), 7 deletions(-) diff --git a/src/outpace/config.clj b/src/outpace/config.clj index 02ec7a5..e004f80 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#)) @@ -302,8 +312,3 @@ (when-let [validate# (-> var# meta :validate)] (validate @var# qname# validate#))) var#))) - -(defmacro defconfig! - "Equivalent to (defconfig ^:required ...)." - [name] - `(defconfig ~(vary-meta name assoc :required true))) From 83ad8c3792903ce73e1f9690e867e9def6600c99 Mon Sep 17 00:00:00 2001 From: Joel Holdbrooks Date: Mon, 1 Apr 2019 15:09:53 -0700 Subject: [PATCH 3/6] Undelete defconfig! --- src/outpace/config.clj | 5 +++++ 1 file changed, 5 insertions(+) diff --git a/src/outpace/config.clj b/src/outpace/config.clj index e004f80..4bed814 100644 --- a/src/outpace/config.clj +++ b/src/outpace/config.clj @@ -312,3 +312,8 @@ (when-let [validate# (-> var# meta :validate)] (validate @var# qname# validate#))) var#))) + +(defmacro defconfig! + "Equivalent to (defconfig ^:required ...)." + [name] + `(defconfig ~(vary-meta name assoc :required true))) From 2a489b6102606e10cc01a2f44988221295dc7cd3 Mon Sep 17 00:00:00 2001 From: Joel Holdbrooks Date: Tue, 2 Apr 2019 10:03:23 -0700 Subject: [PATCH 4/6] Use autogensym --- src/outpace/config.clj | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/src/outpace/config.clj b/src/outpace/config.clj index 4bed814..c5e5070 100644 --- a/src/outpace/config.clj +++ b/src/outpace/config.clj @@ -279,8 +279,8 @@ (if (present? qname#) (alter-var-root var# (constantly (lookup qname#))) (when (and (-> var# meta :required) (not generating?)) - (let [message# (if-let [source (config-source)] - (str "Config var " qname# " must define a default or be specified in " source) + (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))] From c25143a3a5d0b203fe0c8d93c0928dcaf6e6d802 Mon Sep 17 00:00:00 2001 From: Joel Holdbrooks Date: Wed, 24 Apr 2019 17:28:22 -0700 Subject: [PATCH 5/6] Add config-source test --- test/outpace/config_test.clj | 6 ++++++ 1 file changed, 6 insertions(+) diff --git a/test/outpace/config_test.clj b/test/outpace/config_test.clj index 4a81cef..b3fae0c 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 (atom (with-meta {} {:source source}))] + (with-redefs [c/config config] + (is (= source (c/config-source)))))) From 6e6e4e65ea8ed2f8717bf2c292027d79b35a8d72 Mon Sep 17 00:00:00 2001 From: Joel Holdbrooks Date: Wed, 24 Apr 2019 17:29:46 -0700 Subject: [PATCH 6/6] Use delay instead of atom --- test/outpace/config_test.clj | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/test/outpace/config_test.clj b/test/outpace/config_test.clj index b3fae0c..4802bee 100644 --- a/test/outpace/config_test.clj +++ b/test/outpace/config_test.clj @@ -447,6 +447,6 @@ (deftest config-source-test (let [source "config.clj" - config (atom (with-meta {} {:source source}))] + config (delay (with-meta {} {:source source}))] (with-redefs [c/config config] (is (= source (c/config-source))))))