Skip to content

Commit 9df8549

Browse files
committed
Parameterize the println that informs of the fallback cases
1 parent 956a366 commit 9df8549

File tree

1 file changed

+11
-3
lines changed

1 file changed

+11
-3
lines changed

src/pinpointer/core.cljc

Lines changed: 11 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -144,8 +144,12 @@
144144
145145
Takes the same options as pinpoint."
146146
([ed] (pinpoint-out ed {}))
147-
([ed {:keys [width colorize fallback-on-error eval] :as opts
148-
:or {width 70, fallback-on-error true}}]
147+
([ed {:keys [width colorize eval fallback-on-error fallback-reporting-fn] :as opts
148+
:or {width 70
149+
fallback-on-error true
150+
fallback-reporting-fn (fn [_]
151+
(println (str "[PINPOINTER] Failed to analyze the spec errors, "
152+
"and will fall back to s/explain-printer\n")))}}]
149153
(if ed
150154
(let [{:keys [::s/problems ::s/value] :as ed'} (correct-paths ed)
151155
nproblems (count problems)
@@ -171,7 +175,8 @@
171175
":" (:line caller) ")")))))
172176

173177
fallback-on-error
174-
(do (println "[PINPOINTER] Failed to analyze the spec errors, and will fall back to s/explain-printer\n")
178+
(do (fallback-reporting-fn {:explain-data ed
179+
:exception traces})
175180
(s/explain-printer ed))
176181

177182
:else (throw traces)))
@@ -190,6 +195,9 @@ The opts map may have the following keys:
190195
:fallback-on-error - If set to true, falls back to
191196
s/explain-printer in case of an error during the analysis.
192197
Otherwise, rethrows the error. Defaults to true.
198+
:fallback-reporting-fn - A fn (which takes as an argument a map with `:explanation-data` and `:exception` keys)
199+
which reports that pinpointer is falling back to clojure.spec
200+
to reports error. Defaults to a println with a fixed message.
193201
:eval - eval fn to be used to analyze spec errors. Defaults to
194202
clojure.core/eval in Clojure, nil in ClojureScript."
195203
([spec x] (pinpoint spec x {}))

0 commit comments

Comments
 (0)