This page is not created by, affiliated with, or supported by Slack Technologies, Inc.
2023-05-24
Channels
- # aleph (1)
- # beginners (43)
- # calva (22)
- # cider (51)
- # clerk (1)
- # clj-kondo (20)
- # clojure (29)
- # clojure-denmark (1)
- # clojure-europe (73)
- # clojure-finland (28)
- # clojure-nl (1)
- # clojure-norway (7)
- # clojure-spec (7)
- # clojure-uk (4)
- # clojurescript (12)
- # data-science (2)
- # datomic (51)
- # events (1)
- # fulcro (20)
- # hyperfiddle (28)
- # integrant (6)
- # malli (20)
- # matrix (2)
- # music (1)
- # off-topic (66)
- # reitit (17)
- # releases (5)
- # ring (1)
- # shadow-cljs (31)
- # xtdb (6)
A couple of questions in 🧵 on this simple example:
(def ex-spec-1
[:map [:foo :keyword]])
(def ex-spec-2
[:* ex-spec-1])
(m/explain ex-spec-2 [{:foo 3} {:foo :a}])
which returns:
{:schema [:* [:map [:foo :keyword]]],
:value [{:foo 3} {:foo :a}],
:errors
({:path [0 :foo], :in [0 :foo], :schema :keyword, :value 3}
{:path [],
:in [0],
:schema [:* [:map [:foo :keyword]]],
:value {:foo 3},
:type :malli.core/input-remaining})}
1. you can see that in the schema
key in the return value the definition of the schema is expanded out. This is fine in this case, but when you have a lot of nested schema definitions, that becomes a couple pages of unreadable mess. Is there a way I can stop displaying at the first level, in this case [:* ex-spec-1]
?
2. is there ever a difference between defining specs how I did it above wrapping the vector specification with malli.core/schema
, like (m/schema [:map [:foo :keyword]])
? What's the benefit of having both versions?
3. what's the :malli.core/input-remaining
error about? Just signaling that there might be other errors?
3: input-remaining means that the :*
sequence expression didn't manage to consume the whole sequence, i.e. there was extra stuff left over
2: if you use malli functions, they'll call m/schema for you, which will result in the schema getting recompiled. That can be a performance problem if the schema is big or used really often. Other than that, it doesn't matter.
1: that's a good question. I sometimes end up dissocing :schema from my errors because it's not helping. Using a custom registry might help, but I haven't tried it.
Yes, thank you very much @US1LTFF6D!
I'll share here if I end up with a solution for 1, but in the meantime I'll probably dissoc schema too!
there's also me/humanize
Yes, thank @UEENNMX0T, I'm using this from (dev/start! {:report (pretty/reporter)})
so the errors appear automatically in my repl when I run instrumented code. I usually find humanized messages a bit of a hit-or-miss. Many times it's just "Invalid type" 😂
yeah i wish the humanized errors were better about telling you the difference
but they're better than vomiting 10 mb of edn into my console lol
A trick I use for humanization is to print out the received value. You do that by calling humanize with a :wrap
function like so:
(me/humanize
(m/explain input args)
{:wrap
(fn [{:keys [value message]}]
(str message ", received : " (pr-str value)))})
it doesn’t always help, but it can help figure out which part of your value was incorrect