I used the last days to dig deeper into clojure.spec in Clojure and ClojureScript.
Until now I find it most useful, to use specs as guards in :pre
and :post
in public functions that rely on data in a certain format.
(defn person-name [person]
{:pre [(s/valid? ::person person)]
:post [(s/valid? string? %)]}
(str (::first-name person) " " (::last-name person)))
The issue with that approach is, that I get a java.lang.AssertionError: Assert failed: (s/valid? ::person person)
without any information about what exactly did not met the specification.
Has anyone an idea how to get a better error message in :pre
or :post
guards?
I know about conform
and explain*
, but that does not help in those :pre
or :post
guards.