would there be any interest in a patch to add an assert that allowed for data in an ex-info
rather than just a message string?
I don't follow
(assert (every? symbol? gs) (str "Invalid predicate expression " gs))
from core match.
vs
(assert (every? symbol? gs) {:pattern p :predicate-expression gs})
gotta start with a problem
I have no idea what the context is
is there a problem in ex-info
in core or something with core match?
no. but asserts used for constraint violations are convenient and feel right. But when the constraint is violated you can only give a string message rather than the richer data structure that ex-info
allows
hate to be a broken record, but I'm still lost
I'm guessing that there is some stringy exception somewhere that you want to have richer data?
understood. i'll put more clarity into it later
donde? core.match?
used that for a public example. in our codebase, we assert colls/only
, that a collection only had a single value. like the results of a query that you expect to return a single value. Would be nice if we could include the clause that violated the constraint in our message rather than just pr-str'ing it
oh you want assert
itself to throw some rich data
right
ex-info
is an Exception
, assert
throws an Error
the assert could throw an AssertionError subclass that implements IExceptionInfo
but Errors
are not supposed to be caught
An Error is a subclass of Throwable that indicates serious problems that a reasonable application should not try to catch
so having a payload doesn't seem that worthy if you're not supposed to be able to access it
our use case is that our logging infra displays that stuff nicely in addition to the stacktrace. versus just a string
its a simple macro away. that's a good consideration i hadn't thought of. thanks @bronsa