-
Notifications
You must be signed in to change notification settings - Fork 21
Description
Hi!
First to give a bit of context, I find myself writing something like the following in every other project:
i.e throw an expounded-powered runtime exception if spec/valid?
fails. Probably it's a common pattern.
Now, the error messages obtained with this technique are nice, but they could be even better.
For the (check! string? (:foo (do-it 42)))
input:
Current
:the/namespace: -- Spec failed --------------------
nil
should satisfy
string?
[...]
Desired
:the/namespace: -- Spec failed --------------------
nil
evaluated from
(:foo (do-it 42))
should satisfy
string?
[...]
The "evaluated from" bit tells us what expression (e.g. which function argument) did evaluate to nil. Basically that's what we humans do when debugging these expound errors: we try to find the compile-time expression which caused the nil value.
Note that the check!
function I linked to is a function, so I can't access compile-time info.
Now, I could turn it into a macro. Probably pretty easily I could achieve what I want. Now, the only pain point is concatenating my information with expound's information. Manipulating strings is dirty.
So I was thinking, why don't we provide in Expound something akin to my tiny check!
helper, allowing for a clean report which includes the desired extra info.
As a nice side-effect, we'd get a "canonical" check!
- not ideal having to copy/paste it, or authoring yet another "spec utils library".
WDYT? PR welcome?
Cheers - Victor