Fork me on GitHub
#clojure-spec
<
2019-06-29
>
kenny00:06:54

I'm encountering a strange error when using st/check. I'm getting an IllegalArgumentException with the message Additional data must be non-nil. (full trace here: https://gist.github.com/kennyjwilli/e7fcfb809a771db130a1ff37b3d3cb79). The stacktrace points to this line: https://github.com/clojure/spec.alpha/blob/5228bb75fa10b7b13ea088d84f4d031cce74a969/src/main/clojure/clojure/spec/test/alpha.clj#L280 which clearly has the possibility of passing nil to an ex-info call which would result in this error. Not sure why this is happening in the first place though. It's likely an issue in my code but this exception is not very helpful.

Alex Miller (Clojure team)01:06:27

A value that is invalid according to its spec should always produce explain data. Would be interested to know the spec/value causing this

Daniel Hines18:06:24

Can anyone offer any advice on how to transform a json object into a proper Clojure object based on a given spec? The final result has a mix of keywords and strings, and I’m not sure how to say “Here’s a spec of the end result, and here’s the JSON, now give me the end result”

jaihindhreddy20:06:06

not sure how to do it with vanilla spec but Metosin's spec-tools has coercion for this purpose, check out https://github.com/metosin/spec-tools/blob/master/docs/01_coercion.md

Daniel Hines20:06:17

Thanks. Speaking of, how do you get data specs to work with test.check and generators? Is that possible?

Daniel Hines20:06:00

For example, this confuses me:

(s/def ::foo #{:bar})
(s/def ::foo-map (s/keys :req [::foo]))
(gen/generate (s/gen ::foo-map)) ;; => {::foo :bar}
(def data-foo (ds/spec {::foo (s/spec #{:bar})}))
(s/valid? foo-map {::foo :bar}) ;; => true
(gen/generate (s/gen data-foo)) ;; => nil

jaihindhreddy20:06:04

I've only been watching spec-tools and schema from afar. Sorry

Daniel Hines20:06:26

Thanks anyway!

👍 4
Daniel Hines20:06:43

Looks like it’s something to do with this. options include one :gen. https://github.com/metosin/spec-tools/blob/master/docs/07_spec_records.md

💯 4