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 @@
(pprint-to-str 'green some-obj)"
(^String [x]
(when x
(with-out-str
#_{:clj-kondo/ignore [:discouraged-var]}
(pprint/pprint x))))
(with-out-str
#_{:clj-kondo/ignore [:discouraged-var]}
(pprint/pprint x)))
(^String [color-symb x]
(u.format/colorize color-symb (pprint-to-str x))))
......
......@@ -27,17 +27,18 @@
;; not all schemas can generate values
(catch #?(:clj Exception :cljs js/Error) _ ::none))))
([schema 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)]
(cond
;; functions are not going to work
(re-find #"#function" url) nil
;; cant be too long
(<= 2000 (count url)) nil
:else url))))
(when schema
(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)]
(cond
;; functions are not going to work
(re-find #"#function" url) nil
;; cant be too long
(<= 2000 (count url)) nil
:else url)))))
(core/defn- humanize-include-value
"Pass into mu/humanize to include the value received in the error message."
......@@ -50,14 +51,14 @@
[type data]
(let [{:keys [input args output value]} data
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
(pr-str humanized)
(merge {:type type :data data}
(when data
{:link (cond input (->malli-io-link input args)
output (->malli-io-link output value))
:humanized humanized}))))))
(cond-> {:type type :data data}
data (assoc :humanized humanized)
(and data link) (assoc :link link))))))
#?(:clj
(core/defn- -defn [schema args]
......
......@@ -158,3 +158,11 @@
(is (= "map where {:ltf-key -> <Special Number that has to be less than four>}"
(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