Fork me on GitHub

Hi, I have a schema that looks like this:

(def MySchema [:or
                  [:vector any?]
                  [:fn {:error/fn
                        (fn [{:keys [value]} _]
                          (str "Not found: " (pr-str value)))}


When I run (-> (m/explain MySchema 42) (me/humanize)) the result is ["should be a string" "invalid type" "Not found: 42"]


What I’m hoping for is a way to organize the schema so that the error is something like “should be a string or a vector”, and if the value is a vector and my-lookup fails the error is simply “Not found: [:whatever]“. Is there a way to do this?


(also it would be nice if my-lookup didn’t get called if the value wasn’t a vector. I suppose [:and] does not short-circuit)


I suppose I could replace my-lookup with #(or (not (vector? %)) (my-lookup %)), then put an :error/fn on the :vector check that returns “should be a vector”.


Still interested if there’s a more elegant way to do this, though.


@jkrasnay there is a hidden feature where you can add the error-properties into parent-nodes: in case a child errors, the too-most error is used instead, once for all errors. I was not happy with the impl and didn't need it in my client project, so decided not to release it.


OK, thanks. I’ll take some time to study these.


:and and :or short-circuit & collect all errors - it would be easy to inject extra data to those explanations and add options to either schema itself (via properties) or the me/humanize to allow control how to work with them.


Hello there, I've just started a very basic template with Shadow-cljs and Malli , but as I run npx shadow-cljs watch :app I get an error saying : *Wrong number of args (3) passed to malli.core/-fail!* . The project itself is just here : (on the master branch) , and I've stuck [metosin/malli "0.6.1"] in shadow-cljs.edn , is this correct? Any help is much appreciated.


oh well, released version with just the minimal fixes for that @shamansandtheprimes :

➜  ~ clj -Sforce -Sdeps '{:deps {metosin/malli {:mvn/version "0.6.2"}}}'
Downloading: metosin/malli/0.6.2/malli-0.6.2.pom from clojars