bhb / expound

Human-optimized error messages for clojure.spec
Eclipse Public License 1.0
924 stars 24 forks source link

make defmsg work for for any qualified-ident? and/or form + make it traverse spec keys #234

Closed mpenet closed 2 years ago

mpenet commented 2 years ago

This also makes defmsg check all spec value in the spec "path"

(s/def ::str string?)
(s/def ::foo ::str)
(s/def ::bar ::foo)

if a defmsg is set on ::bar it will return that one first, if none is set on on ::bar, then it would check for one on ::foo, then on ::str, and ultimately on `string?

It also allows to set messages for full forms, so you can add a defmsg on 'clojure.core/string? '(s/coll-of string?) etc (as demonstrated in tests).

To make this happen a expound.util/spec-vals function is implemented that will return a lazyseq of keys related to a spec, starting with the spec key in question:

(spec-vals ::bar) would return (::bar ::foo ::str 'clojure.core/string?) from there error-message will check for these keys in the message registry until there is match.