Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Failure spec checking fails for functions returning collections #14

Open
kliramu opened this issue May 30, 2018 · 2 comments
Open

Failure spec checking fails for functions returning collections #14

kliramu opened this issue May 30, 2018 · 2 comments

Comments

@kliramu
Copy link

kliramu commented May 30, 2018

examples use defn-spec from orchestra
This works:

(defn-spec test-failure-works (s/or :ok string? :fail ::fs/failure)
  []
  (f/fail "something wrong"))

This does not work --looks like the invocation of 'empty' on Failure record from the clojure.spec code is the problem:

(defn-spec test-failure-doesnt-work (s/or :ok (s/coll-of string?) :fail ::fs/failure)
  []
  (f/fail "something wrong"))

Unhandled java.lang.UnsupportedOperationException
Can't create empty: failjure.core.Failure

            core.clj:   36  failjure.core.Failure/empty
            core.clj: 5187  clojure.core/empty
            core.clj: 5181  clojure.core/empty
           alpha.clj: 1229  clojure.spec.alpha/every-impl/cfns/fn
           alpha.clj: 1243  clojure.spec.alpha/every-impl/reify
           alpha.clj: 1017  clojure.spec.alpha/or-spec-impl/fn
           alpha.clj: 1052  clojure.spec.alpha/or-spec-impl/reify
           alpha.clj:  150  clojure.spec.alpha/conform
           alpha.clj:  146  clojure.spec.alpha/conform
            test.clj:   97  orchestra.spec.test/spec-checking-fn/conform!
            test.clj:  125  orchestra.spec.test/spec-checking-fn/fn
         RestFn.java:  397  clojure.lang.RestFn/invoke
@adambard
Copy link
Owner

Interesting, I'll have to dig into this. I'd rather not implement unused collection functions on Failure just in case someone tries to treat it this way, but I guess if the alternative is that it crashes for this reasonable use case I have no choice.

In the meantime, does this work if you do (s/or :fail ::fs/failure :ok (s/coll-of string?)) instead?

@kliramu
Copy link
Author

kliramu commented May 30, 2018

Yes, putting the failure option first is working!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants