Fork me on GitHub
#clojure-dev
<
2020-07-09
>
dpsutton20:07:03

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?

ghadi21:07:30

I don't follow

dpsutton21:07:24

(assert (every? symbol? gs) (str "Invalid predicate expression " gs)) from core match. vs (assert (every? symbol? gs) {:pattern p :predicate-expression gs})

ghadi21:07:57

gotta start with a problem

ghadi21:07:18

I have no idea what the context is

ghadi21:07:29

is there a problem in ex-info in core or something with core match?

dpsutton21:07:33

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

ghadi21:07:43

hate to be a broken record, but I'm still lost

ghadi21:07:00

I'm guessing that there is some stringy exception somewhere that you want to have richer data?

dpsutton21:07:04

understood. i'll put more clarity into it later

3
ghadi21:07:06

donde? core.match?

dpsutton21:07:18

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

ghadi21:07:48

oh you want assert itself to throw some rich data

bronsa21:07:28

ex-info is an Exception, assert throws an Error

favila21:07:03

the assert could throw an AssertionError subclass that implements IExceptionInfo

bronsa21:07:25

but Errors are not supposed to be caught

bronsa21:07:38

An Error is a subclass of Throwable that indicates serious problems that a reasonable application should not try to catch

bronsa21:07:08

so having a payload doesn't seem that worthy if you're not supposed to be able to access it

dpsutton21:07:50

our use case is that our logging infra displays that stuff nicely in addition to the stacktrace. versus just a string

dpsutton21:07:35

its a simple macro away. that's a good consideration i hadn't thought of. thanks @bronsa