This page is not created by, affiliated with, or supported by Slack Technologies, Inc.
2019-06-29
Channels
- # announcements (1)
- # beginners (40)
- # calva (30)
- # cider (3)
- # clj-kondo (1)
- # cljdoc (12)
- # clojure (79)
- # clojure-dev (7)
- # clojure-france (4)
- # clojure-spec (10)
- # clojure-uk (13)
- # clojurescript (19)
- # core-async (1)
- # core-typed (1)
- # cursive (2)
- # datomic (2)
- # emacs (3)
- # events (1)
- # kaocha (2)
- # klipse (14)
- # off-topic (26)
- # pathom (1)
- # reagent (8)
- # rewrite-clj (8)
- # shadow-cljs (22)
- # tools-deps (18)
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.
A value that is invalid according to its spec should always produce explain data. Would be interested to know the spec/value causing this
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”
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
Thanks. Speaking of, how do you get data specs to work with test.check and generators? Is that possible?
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
I've only been watching spec-tools and schema from afar. Sorry
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