Fork me on GitHub

What is the right way to spec functions that can throw exceptions? It seems like I need to allow :ret to be nil to handle exceptions here

Alex Miller (Clojure team)16:05:51

If there is an exception there is no return value

Alex Miller (Clojure team)16:05:14

Exceptions are not covered by spec

Alex Miller (Clojure team)16:05:36

Because they are ... exceptional cases


hai all, how do we handle ordering with spec?

Alex Miller (Clojure team)17:05:44

you’ll need to explain more, not sure what you mean


(s/and sorted? ...)?


(not the clojure.core/sorted?)


Is this expected?

(let [n 2
      t int?]
  (s/conform (s/coll-of t :into [] :kind vector? :count n) [1 2]))
=> [1 2]

(let [n nil
      t int?]
  (s/conform (s/coll-of t :into [] :kind vector? :count n) [1 2]))
=> :clojure.spec.alpha/invalid

(let [t int?]
  (s/conform (s/coll-of t :into [] :kind vector? :count nil) [1 2]))
=> [1 2]


I just wonder if this is a bug, or if the s/every macro is meant to check the 'n symbol rather than what it evals to.

Alex Miller (Clojure team)19:05:03

I think I’d call it a bug, given the docstring states that nil is the default which seems to imply you could pass it

Alex Miller (Clojure team)19:05:07

feel free to file a jira


Ok, will do. Thanks