This page is not created by, affiliated with, or supported by Slack Technologies, Inc.
2021-09-27
Channels
- # announcements (2)
- # asami (25)
- # babashka (124)
- # beginners (46)
- # calva (55)
- # cljdoc (70)
- # clojure (68)
- # clojure-australia (2)
- # clojure-dev (63)
- # clojure-europe (38)
- # clojure-nl (1)
- # clojure-spec (1)
- # clojure-uk (8)
- # clojurescript (56)
- # community-development (4)
- # conjure (1)
- # copenhagen-clojurians (1)
- # core-async (1)
- # cursive (3)
- # datahike (5)
- # datomic (183)
- # depstar (2)
- # figwheel-main (10)
- # fulcro (20)
- # honeysql (2)
- # hyperfiddle (1)
- # integrant (68)
- # jobs (6)
- # jobs-discuss (5)
- # juxt (1)
- # malli (13)
- # off-topic (8)
- # pathom (2)
- # rdf (10)
- # reagent (11)
- # remote-jobs (1)
- # rum (1)
- # shadow-cljs (69)
- # spacemacs (1)
- # sql (5)
- # tools-build (51)
- # tools-deps (6)
- # xtdb (24)
Hi, I have a schema that looks like this:
(def MySchema [:or
:string
[:and
[:vector any?]
[:fn {:error/fn
(fn [{:keys [value]} _]
(str "Not found: " (pr-str value)))}
my-lookup]]])
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”.
@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.
try: https://github.com/metosin/malli/blob/master/test/malli/error_test.cljc#L499-L524
: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 : https://github.com/bitbot123/shadow-cljs-malli/blob/master/src/core.cljs (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