Fork me on GitHub
#malli
<
2023-08-01
>
pavlosmelissinos19:08:48

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!

pavlosmelissinos19:08:32

(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.

pavlosmelissinos20:08:28

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})}

ikitommi08:08:45

good catch, I think that’s more correct. please write an issue out of this

pavlosmelissinos08:08:41

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
Joel23:08:13

How could I figure out the type of :x? Either from the registry “directly” or after turning into a schema.

(m/schema [:schema {:registry {:x :int}} :x])

Joel02:08:44

It appears the relevant function I need is deref

👍 1