From 0f3ea6c79b76a84be45334c87f06ae7af83d2707 Mon Sep 17 00:00:00 2001 From: Nathan Marz Date: Tue, 5 Jan 2016 08:57:27 -0500 Subject: [PATCH] throw error if function names incorrectly specified in defpath, improve formatting of error messages --- src/clj/com/rpl/specter/impl.cljx | 10 +++++++++- src/clj/com/rpl/specter/macros.clj | 3 +++ 2 files changed, 12 insertions(+), 1 deletion(-) diff --git a/src/clj/com/rpl/specter/impl.cljx b/src/clj/com/rpl/specter/impl.cljx index d78627d..84b592f 100644 --- a/src/clj/com/rpl/specter/impl.cljx +++ b/src/clj/com/rpl/specter/impl.cljx @@ -23,9 +23,17 @@ (defprotocol PathComposer (comp-paths* [paths])) +(defn- smart-str* [o] + (if (coll? o) + (pr-str o) + (str o))) + +(defn smart-str [& elems] + (apply str (map smart-str* elems))) + #+clj (defmacro throw* [etype & args] - `(throw (new ~etype (pr-str ~@args)))) + `(throw (new ~etype (smart-str ~@args)))) #+clj (defmacro throw-illegal [& args] diff --git a/src/clj/com/rpl/specter/macros.clj b/src/clj/com/rpl/specter/macros.clj index b25738a..a8d5141 100644 --- a/src/clj/com/rpl/specter/macros.clj +++ b/src/clj/com/rpl/specter/macros.clj @@ -6,6 +6,9 @@ (vec (repeatedly amt gensym))) (defn determine-params-impls [[name1 & impl1] [name2 & impl2]] + (if-not (= #{name1 name2} #{'select* 'transform*}) + (throw-illegal "defpath must implement select* and transform*, instead got " + name1 " and " name2)) (if (= name1 'select*) [impl1 impl2] [impl2 impl1]))