Skip to content

Commit

Permalink
Merge pull request #738 from metosin/mask-valid-values-by-default
Browse files Browse the repository at this point in the history
mask valid values by default with malli.dev.pretty/explain
  • Loading branch information
ikitommi authored Aug 11, 2022
2 parents bb7e401 + f5a16e8 commit 5e8e389
Show file tree
Hide file tree
Showing 3 changed files with 29 additions and 16 deletions.
18 changes: 9 additions & 9 deletions src/malli/dev/pretty.cljc
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,8 @@
:width 100
:colors v/-dark-colors
:unknown (fn [x] (when (m/schema? x) (m/form x)))
:throwing-fn-top-level-ns-names ["malli" "clojure"]}
:throwing-fn-top-level-ns-names ["malli" "clojure" "malli"]
::me/mask-valid-values '...}
options))))

(defn -errors [explanation printer]
Expand All @@ -30,14 +31,13 @@
;; formatters
;;

(defmethod v/-format ::m/explain [_ _ explanation printer]
(let [{:keys [schema value]} explanation]
{:body
[:group
(-block "Errors:" (v/-visit (me/humanize explanation) printer) printer) :break :break
(-block "Value:" (v/-visit value printer) printer) :break :break
(-block "Schema:" (v/-visit schema printer) printer) :break :break
(-block "More information:" (-link "https://cljdoc.org/d/metosin/malli/CURRENT" printer) printer)]}))
(defmethod v/-format ::m/explain [_ _ {:keys [schema] :as explanation} printer]
{:body
[:group
(-block "Value:" (v/-visit (me/error-value explanation printer) printer) printer) :break :break
(-block "Errors:" (v/-visit (me/humanize explanation) printer) printer) :break :break
(-block "Schema:" (v/-visit schema printer) printer) :break :break
(-block "More information:" (-link "https://cljdoc.org/d/metosin/malli/CURRENT" printer) printer)]})

(defmethod v/-format ::m/invalid-input [_ _ {:keys [args input fn-name]} printer]
{:body
Expand Down
9 changes: 2 additions & 7 deletions src/malli/dev/virhe.cljc
Original file line number Diff line number Diff line change
Expand Up @@ -111,7 +111,7 @@
:print-length *print-length*
:print-level *print-level*
:print-meta *print-meta*}]
(map->EdnPrinter (cond->> options defaults (merge defaults))))))
(map->EdnPrinter (cond-> defaults options (merge options))))))

(defn -pprint
([x] (-pprint x (-printer)))
Expand Down Expand Up @@ -158,12 +158,7 @@
(-color :text body printer))

(defn -section [title location body printer]
[:group
(-title title location printer)
:break :break
body
:break :break
(-footer printer)])
[:group (-title title location printer) :break :break body :break :break (-footer printer)])

;;
;; formatting
Expand Down
18 changes: 18 additions & 0 deletions test/demo.clj
Original file line number Diff line number Diff line change
Expand Up @@ -15,3 +15,21 @@
{:name "Endy"
:age 17
:home {:zip 33100}}))

(comment
(pretty/explain
[:map
[:id :int]
[:tags [:set :keyword]]
[:address [:map
[:street :string]
[:city :string]
[:zip :int]
[:lonlat [:tuple :double :double]]]]]
{:id "123"
:EXTRA "KEY"
:tags #{:artesan "coffee" :garden}
:address {:street "Ahlmanintie 29"
:city "Tampere"
:zip 33100
:lonlat [61.4858322, 23.7832851]}}))

0 comments on commit 5e8e389

Please sign in to comment.