Skip to content
Snippets Groups Projects
Unverified Commit eab2af99 authored by Bryan Maass's avatar Bryan Maass Committed by GitHub
Browse files

fixes nil schema being passed into ->malli-io-link (#28542)

* fixes nil schema being passed into ->malli-io-link

- happens when function args aren't annotated.

* (u/pprint-to-str nil) should be "nil\n", not nil
parent 0c566648
No related branches found
No related tags found
No related merge requests found
...@@ -559,10 +559,9 @@ ...@@ -559,10 +559,9 @@
(pprint-to-str 'green some-obj)" (pprint-to-str 'green some-obj)"
(^String [x] (^String [x]
(when x (with-out-str
(with-out-str #_{:clj-kondo/ignore [:discouraged-var]}
#_{:clj-kondo/ignore [:discouraged-var]} (pprint/pprint x)))
(pprint/pprint x))))
(^String [color-symb x] (^String [color-symb x]
(u.format/colorize color-symb (pprint-to-str x)))) (u.format/colorize color-symb (pprint-to-str x))))
......
...@@ -27,17 +27,18 @@ ...@@ -27,17 +27,18 @@
;; not all schemas can generate values ;; not all schemas can generate values
(catch #?(:clj Exception :cljs js/Error) _ ::none)))) (catch #?(:clj Exception :cljs js/Error) _ ::none))))
([schema value] ([schema value]
(let [url-schema (encode-uri (u/pprint-to-str (mc/form schema))) (when schema
url-value (if (= ::none value) (let [url-schema (encode-uri (u/pprint-to-str (mc/form schema)))
"" url-value (if (= ::none value)
(encode-uri (u/pprint-to-str value))) ""
url (str "https://malli.io?schema=" url-schema "&value=" url-value)] (encode-uri (u/pprint-to-str value)))
(cond url (str "https://malli.io?schema=" url-schema "&value=" url-value)]
;; functions are not going to work (cond
(re-find #"#function" url) nil ;; functions are not going to work
;; cant be too long (re-find #"#function" url) nil
(<= 2000 (count url)) nil ;; cant be too long
:else url)))) (<= 2000 (count url)) nil
:else url)))))
(core/defn- humanize-include-value (core/defn- humanize-include-value
"Pass into mu/humanize to include the value received in the error message." "Pass into mu/humanize to include the value received in the error message."
...@@ -50,14 +51,14 @@ ...@@ -50,14 +51,14 @@
[type data] [type data]
(let [{:keys [input args output value]} data (let [{:keys [input args output value]} data
humanized (cond input (me/humanize (mc/explain input args) {:wrap humanize-include-value}) humanized (cond input (me/humanize (mc/explain input args) {:wrap humanize-include-value})
output (me/humanize (mc/explain output value) {:wrap humanize-include-value}))] output (me/humanize (mc/explain output value) {:wrap humanize-include-value}))
link (cond input (->malli-io-link input args)
output (->malli-io-link output value))]
(throw (ex-info (throw (ex-info
(pr-str humanized) (pr-str humanized)
(merge {:type type :data data} (cond-> {:type type :data data}
(when data data (assoc :humanized humanized)
{:link (cond input (->malli-io-link input args) (and data link) (assoc :link link))))))
output (->malli-io-link output value))
:humanized humanized}))))))
#?(:clj #?(:clj
(core/defn- -defn [schema args] (core/defn- -defn [schema args]
......
...@@ -158,3 +158,11 @@ ...@@ -158,3 +158,11 @@
(is (= "map where {:ltf-key -> <Special Number that has to be less than four>}" (is (= "map where {:ltf-key -> <Special Number that has to be less than four>}"
(umd/describe special-lt-4-schema))))))) (umd/describe special-lt-4-schema)))))))
(deftest ->malli-io-link-test
(is (= nil
(#'mu/->malli-io-link nil nil)))
(is (= nil
(#'mu/->malli-io-link nil :string)))
(is (= "https://malli.io?schema=%3Astring%0A&value=nil%0A"
(#'mu/->malli-io-link :string nil))))
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment