Skip to content

Parameterize the println that informs of the fallback cases #10

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
wants to merge 2 commits into
base: master
Choose a base branch
from
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
16 changes: 12 additions & 4 deletions src/pinpointer/core.cljc
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand All @@ -171,11 +175,12 @@
":" (: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)))
(println "Success!!"))))
(println "Success!"))))

(defn pinpoint
"Given a spec and a value that fails to conform, reports the spec
Expand All @@ -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 {}))
Expand Down