On 10 February 2011 17:05, Jeff Rose <ros...@gmail.com> wrote: > Sorry for the reply spam, but I've just remembered another error > reporting issue: pre and post conditions. They are a great feature > and I'd like to use them more often, but the error messages they > produce are virtually useless in comparison to just writing your own > check with a custom exception. How about having optional error > messages for the conditions?
You can make your pre/post condition AssertionErrors more human-readable by factoring out their logic into helper functions: (defn valid-article-id? [art-id] (or (and (> (mod x 42) 3) (frobz x)) (qux x))) (defn buy-article [art-id] {:pre [(valid-article-id? art-id)]} ...) Thus, the AssertionError message will complain about "valid-article-id?" failing instead of the rather cryptic "or and mod". If you need even more flexibility, it is also possible to throw an exception from the helper function. Not pretty, though. That said, I'd really wish for the private clojure.core/assert-args macro to be made public. It's very comfortable to work with and provides for semi-standardized error messages (offending argument name always in front). -- You received this message because you are subscribed to the Google Groups "Clojure" group. To post to this group, send email to clojure@googlegroups.com Note that posts from new members are moderated - please be patient with your first post. To unsubscribe from this group, send email to clojure+unsubscr...@googlegroups.com For more options, visit this group at http://groups.google.com/group/clojure?hl=en