This page is not created by, affiliated with, or supported by Slack Technologies, Inc.
2023-08-01
Channels
- # announcements (1)
- # babashka (18)
- # babashka-sci-dev (10)
- # beginners (17)
- # clj-on-windows (21)
- # clj-yaml (4)
- # cljs-dev (33)
- # cljsrn (2)
- # clojure (51)
- # clojure-austin (3)
- # clojure-doc (22)
- # clojure-europe (17)
- # clojure-greece (4)
- # clojure-norway (6)
- # clr (4)
- # conjure (7)
- # datalog (14)
- # emacs (11)
- # hyperfiddle (121)
- # introduce-yourself (1)
- # kaocha (1)
- # malli (8)
- # practicalli (1)
- # releases (1)
- # shadow-cljs (26)
- # squint (2)
Hi! If you m/explain
invalid data using a multi-schema, the explainer shows the entire multi-schema, not just the matching part. This can make spotting errors harder.
Wouldn't it be better to just use the part that is relevant when there's a clear dispatch value? :thinking_face: Example in thread!
(m/explain
[:multi {:dispatch :type}
[:sized [:map [:type keyword?] [:size int?]]]
[:human [:map [:type keyword?] [:name string?] [:address [:map [:country keyword?]]]]]]
{:type :sized, :sizey 10})
If you run this (took it from the malli README and added a typo to the data so that it throws an exception), you'll get a message that tells you that the map is an invalid ":sized OR :human"
I think it would be an improvement if malli could understand that the map is obviously a :sized
in this case, so I don't need to be shown any information about :human
.I.e., instead of this:
{:schema [:multi {:dispatch :type} [:sized [:map [:type keyword?] [:size int?]]] [:human [:map [:type keyword?] [:name string?] [:address [:map [:country keyword?]]]]]], :value {:type :sized, :sizey 10}, :errors ({:path [:sized :size], :in [:size], :schema [:map [:type keyword?] [:size int?]], :value nil, :type :malli.core/missing-key})}
I'd prefer this:
{:schema [:sized [:map [:type keyword?] [:size int?]]], :value {:type :sized, :sizey 10}, :errors ({:path [:sized :size], :in [:size], :schema [:map [:type keyword?] [:size int?]], :value nil, :type :malli.core/missing-key})}
Thanks for the confirmation! I'm away from my computer right now but I'll make an issue as soon as I get back!
👍 2
FYI, voila! https://github.com/metosin/malli/issues/923 edit: rephrased it a bit...