Fork me on GitHub
#clojure-spec
<
2017-11-25
>
qqq10:11:23

is there a way to hijack s/assert 's error messages? I often have situations where: 1. obj is a giant data sttructure 2. obj fails spec ::foo 3. the fact that obj fails can be verified by just loloking at (keys obj) 4. s/assert prints out all of obj, which actuall makes it more difficult to see what is going on

bbrinck22:11:04

You can also customize the printer e.g.

(defn my-assert [spec val]
  (binding [s/*explain-out* my-printer]
    (s/assert spec val)))
my-printer will take a single argument that is the explain-data (it’s data like the return value from s/explain-data).

qqq23:11:07

this looks better than what I asked for

qqq23:11:20

so I get to take the assertion failure, as clojure data, rewrite it, then print it out

bbrinck23:11:42

Yep, you can format it however you want

bbrinck23:11:15

Also, if you happen to want an out of the box experience, you can use expound

bbrinck23:11:58

It doesn’t actually help in this specific case (it prints out the entire value when it is missing keys), but you can provide a custom function to print out the value in this specific case

bbrinck23:11:40

in that case, you’ll get the spec-name and some other data, which might be enough to detect this particular case.

bbrinck23:11:33

Or you could even write your own printer which inspects the explain-data and does something custom for keys specs, but passes it along to expound otherwise.

qqq23:11:29

when an assertion happens, I want it to pop up a new browser window, print the first level of the data, have + buttons next to parts that can be expand (and expands when I click on them), and highlights in a red DOM rectangle the key/value pair that is failing the spec

qqq23:11:35

someone needs to build that 🙂

qqq23:11:20

this is amazing

bbrinck00:11:58

No idea, it seems like a great tool, maybe we need a collection of these helper libraries

gfredericks12:11:31

wrap it in a try/catch?

triss13:11:28

how can I look inside the result of an s/and? - I’d like to dig out the s/cat contained within it.

triss13:11:17

lovely thanks!

hmaurer20:11:09

Hi! I am getting a cryptic error (to me) when attempting to build my ClojureScript project for production (with advanced opts). Could someone please take a look? https://gist.github.com/hmaurer/1d30b39c8e28e646ebdfa524cbcdedb6

hmaurer20:11:33

wrong channel, sorry