Fork me on GitHub
#malli
<
2022-09-20
>
hmadelaine09:09:20

Hi everyone ! I have a question regarding malli.error/humanizeand a sequential schema. I have modified the example given in the README. Instead of having a nil latitude, I put a string.

(-> Address
      (m/explain
        {:id      "ID676"
         :tags    #{:artesan :coffee :garden}
         :address {:street "Ahlmanintie 29"
                   :city    "paris"
                   :zip    33100
                   :lonlat [61.4858322, "23.89"]}})
      (me/humanize))
=> {:address {:lonlat [nil ["should be a double"]]}}
I was expecting in the humanized error, this output :
{:address {:lonlat ["23.89" ["should be a double"]]}}
The result of m/explain indicates clearly in the errors that the input “23.89" is incorrect.
{:schema [:map
          [:id string?]
          [:tags [:set keyword?]]
          [:address [:map [:street string?] [:city string?] [:zip int?] [:lonlat [:tuple double? double?]]]]],
 :value {:id "Hiram",
         :tags #{:coffee :artesan :garden},
         :address {:street "Ahlmanintie 29", :city "paris", :zip 33100, :lonlat [61.4858322 "23.89"]}},
 :errors ({:path [:address :lonlat 1], :in [:address :lonlat 1], :schema double?, :value "23.89"})}
Is it normal ? Thnak you very much

ikitommi14:09:00

this is normal, for sequential, nil are used to mask the valid values, e.g. “second and fourth elements in error” = [nil nil ["error"] nil ["error"]]

ikitommi14:09:49

you can configure how to show the valid values, e.g.

(-> Address
    (m/explain
     {:id "Lillan"
      :tags #{:artesan "coffee" :garden "ground"}
      :address {:street "Ahlmanintie 29"
                :zip 33100
                :lonlat [61.4858322, "23.7832851,17"]}})
    (me/error-value {::me/mask-valid-values '...}))
;{:id ...
; :tags #{"coffee" "ground" ...}
; :address {:street ...
;           :zip ...
;           :lonlat [... "23.7832851,17"]}}

hmadelaine14:09:40

Alright ! Thank you very much 👍

hmadelaine14:09:01

It seems that me/error-value is not available in 0.8.9 ?

hmadelaine15:09:03

Do you plan to release malli this month ?

hmadelaine15:09:45

Thank you for the excellent work 🙏