Prismatic/schema — pull request #33 by danielneal (2013-10-08 13:26:14+00:00)
Title: Feature/validation error in ex info

I've had a go at adding ex-info information when validation fails, to fix #30.
Let me know what you think.

Example:
(s/validate [Number] `[1 2 ~@(range 100) "bob"])
ExceptionInfo
Value does not match schema: [nil nil nil nil nil nil nil nil nil
nil nil nil nil nil nil nil nil nil nil nil nil nil nil nil nil nil
nil nil nil nil nil nil nil nil nil nil nil nil nil nil nil nil nil
nil nil nil nil nil nil nil nil nil nil nil nil nil nil nil nil nil
nil nil nil nil nil nil nil nil nil nil nil nil nil nil nil nil nil
nil nil nil nil nil nil nil nil nil nil nil nil nil nil nil nil nil
nil nil nil nil nil nil ...] clojure.core/ex-info (core.clj:4327)

In these cases, it looks impossible to find out what caused the problem as the crucial bit is truncated.

However, now we have an `ExceptionInfo`, not a `RuntimeException`, so we have access to some more info.

(def error-info (ex-data *e))
{:schema [java.lang.Number],
:value [1 2 0 1 2 3 4 5 6 7 8 9 10 11 12 ...],
:error [nil nil nil nil nil nil nil nil nil nil nil ...]}

And although the error-info may print truncated in the REPL, it is genuine clojure data, so we can do this ...

(remove nil? (:error (error-info)))

... and find that it is "bob" that is the cause of all our troubles.

((not (instance? java.lang.Number "bob")))

Note:
There were two tests that didn't pass - but they were like that when I got there, I promise :)