2

I do not understand this concept. malli.error/humanize

I tried following up with the github link of Malli. https://github.com/metosin/malli

Does humanize refer to the error statements that we can customize & add like in Java? Or does it mean that errors are printed in a more readable way?

And this is the code.

 (require '[malli.error :as me])

(-> Address
    (m/explain
      {:id "Lillan"
       :tags #{:artesan "coffee" :garden}
       :address {:street "Ahlmanintie 29"
                 :zip 33100
                 :lonlat [61.4858322, nil]}})
    (me/humanize))
;{:tags #{["should be a keyword"]}
; :address {:city ["missing required key"]
;           :lonlat [nil ["should be a double"]]}}
Blaze
  • 368
  • 1
  • 10
  • 1
    From the readme I get the idea that it produces the same as `m/explain` in a more readable way. It is also customizable so that the error messages are even more readable. – Sylwester Jul 11 '22 at 08:31
  • 1
    The readme https://github.com/metosin/malli#custom-error-messages , from where your example is from, lists many points and examples. It primarily to get "human" friendly messages (other than "machine" friendly, that `exaplin` produces). The result is a datastructure, you have to deal with ("printing" will only help for developers, and it's not clear with what "Java"-feature you are trying to compare this) – cfrick Jul 11 '22 at 08:59
  • @cfrick the java feature I was referring to was a simple try catch block. Was working on a project where we use default error messages for payloads, like null or invalid, etc. Or more specific about what in wrong I payload.. So I was trying to understand humanize enclosure with respect to the project's Java code. – Blaze Jul 11 '22 at 13:25
  • "It primarily to get "human" friendly messages (other than "machine" friendly, that exaplin produces). " This statement was very helpful. – Blaze Jul 11 '22 at 13:26

1 Answers1

2

"Does humanize refer to the error statements that we can customize & add like in Java? Or does it mean that errors are printed in a more readable way?"

So both actually. We can customize it too. And errors are printed in a more human-readable way.

Blaze
  • 368
  • 1
  • 10