From 956a36667343a3d89befaa4a3ba41ae136137f61 Mon Sep 17 00:00:00 2001 From: vemv Date: Fri, 3 Aug 2018 05:13:53 +0200 Subject: [PATCH 1/2] Use just one exclamation point on success message, to match clojure.spec behavior --- src/pinpointer/core.cljc | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/pinpointer/core.cljc b/src/pinpointer/core.cljc index c625596..a7d0511 100644 --- a/src/pinpointer/core.cljc +++ b/src/pinpointer/core.cljc @@ -175,7 +175,7 @@ (s/explain-printer ed)) :else (throw traces))) - (println "Success!!")))) + (println "Success!")))) (defn pinpoint "Given a spec and a value that fails to conform, reports the spec From 9df8549735522fb9fec80b966ef08265e50c9c65 Mon Sep 17 00:00:00 2001 From: vemv Date: Fri, 3 Aug 2018 05:36:05 +0200 Subject: [PATCH 2/2] Parameterize the `println` that informs of the fallback cases --- src/pinpointer/core.cljc | 14 +++++++++++--- 1 file changed, 11 insertions(+), 3 deletions(-) diff --git a/src/pinpointer/core.cljc b/src/pinpointer/core.cljc index a7d0511..61ac7e1 100644 --- a/src/pinpointer/core.cljc +++ b/src/pinpointer/core.cljc @@ -144,8 +144,12 @@ Takes the same options as pinpoint." ([ed] (pinpoint-out ed {})) - ([ed {:keys [width colorize fallback-on-error eval] :as opts - :or {width 70, fallback-on-error true}}] + ([ed {:keys [width colorize eval fallback-on-error fallback-reporting-fn] :as opts + :or {width 70 + fallback-on-error true + fallback-reporting-fn (fn [_] + (println (str "[PINPOINTER] Failed to analyze the spec errors, " + "and will fall back to s/explain-printer\n")))}}] (if ed (let [{:keys [::s/problems ::s/value] :as ed'} (correct-paths ed) nproblems (count problems) @@ -171,7 +175,8 @@ ":" (:line caller) ")"))))) fallback-on-error - (do (println "[PINPOINTER] Failed to analyze the spec errors, and will fall back to s/explain-printer\n") + (do (fallback-reporting-fn {:explain-data ed + :exception traces}) (s/explain-printer ed)) :else (throw traces))) @@ -190,6 +195,9 @@ The opts map may have the following keys: :fallback-on-error - If set to true, falls back to s/explain-printer in case of an error during the analysis. Otherwise, rethrows the error. Defaults to true. + :fallback-reporting-fn - A fn (which takes as an argument a map with `:explanation-data` and `:exception` keys) + which reports that pinpointer is falling back to clojure.spec + to reports error. Defaults to a println with a fixed message. :eval - eval fn to be used to analyze spec errors. Defaults to clojure.core/eval in Clojure, nil in ClojureScript." ([spec x] (pinpoint spec x {}))