Fork me on GitHub
#clojure-spec
<
2016-12-15
>
sveri20:12:55

I wonder if there is a way to make sense of such a spec message: http://pastebin.com/QrU49Thr

sveri20:12:49

its hard to figure out if I am just missing a key somewhere or if the structure in general (coll-of (coll-of ...)) is broken

Alex Miller (Clojure team)20:12:49

I think there might be more than one thing wrong too

Alex Miller (Clojure team)20:12:05

this: val: 16 fails spec: :de.sveri.getless.service.off/id at: [:args :foods :id] predicate: string? seems pretty straightforward

Alex Miller (Clojure team)20:12:14

the :id key is an int not a string

Alex Miller (Clojure team)20:12:32

the foods arg also seems to be missing some keys

:de.sveri.getless.service.off/product at: [:args :foods] predicate: (contains? % :image_small_url)
:de.sveri.getless.service.off/product at: [:args :foods] predicate: (contains? % :image_thumb_url)
:de.sveri.getless.service.off/product at: [:args :foods] predicate: (contains? % :lang)
:de.sveri.getless.service.off/product at: [:args :foods] predicate: (contains? % :code)
:de.sveri.getless.service.off/product at: [:args :foods] predicate: (contains? % :rev)

sveri20:12:44

@alexmiller Yea, thats right, uhm, ok, I am, surprised

sveri20:12:56

Can you tell me how you extracted the important information so quick?

Alex Miller (Clojure team)20:12:16

looking at the line breaks

sveri20:12:21

It took me a lot of time figuring out the first error, then reload and look for the second one. My problem is, its just a wall of text.

Alex Miller (Clojure team)20:12:24

each line is a problem - those are the ends of the lines

sveri20:12:56

I see, turning off soft wraps would have helped here.

Alex Miller (Clojure team)20:12:56

the (large) data value is the distracting part in each line

Alex Miller (Clojure team)20:12:31

you can install a custom explain printer too if you want (could actually hide the val, or limit it’s size)

sveri20:12:08

That sounds good, my application makes use of an external service, that returns a lot of data. Is there an example somewhere on how to make a custom printer?

Alex Miller (Clojure team)20:12:24

(set! s/*explain-out*
  (fn [explain-data]
    (binding [*print-length* 3] 
      (s/explain-printer explain-data))))

Alex Miller (Clojure team)20:12:56

*explain-out* is a dynamic variable holding the function that prints explain data

Alex Miller (Clojure team)20:12:31

^^ that will work at the repl, but you might need to use with-bindings to make it work in your code

Alex Miller (Clojure team)20:12:47

s/explain-printer is the default print function

Alex Miller (Clojure team)20:12:05

this example limits *print-length* to 3 when printing big collections

Alex Miller (Clojure team)20:12:13

(that’s the most common source of large printed values)

Alex Miller (Clojure team)20:12:59

for example (s/explain empty? (range 100)) with the above will not print the full seq

sveri20:12:07

Awesome 🙂 First question, may I put that on a gist with your comments and second: when I try your code it throws the following exception during runtime: java.lang.IllegalStateException: Can't change/establish root binding of: *explain-out* with set

Alex Miller (Clojure team)20:12:28

Yes and that's what I mentioned

Alex Miller (Clojure team)20:12:05

It works at the repl because the repl binds explain-out

Alex Miller (Clojure team)20:12:55

But in your code you need to set it in a dynamic scope with something like binding

Alex Miller (Clojure team)20:12:36

I should probably just write a quick blog on it

sveri20:12:26

@alexmiller Great, I got it now 🙂 thank you very much