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

Improve grouping of spec errors #165

Closed
kelvinqian00 opened this issue Aug 5, 2019 · 2 comments
Closed

Improve grouping of spec errors #165

kelvinqian00 opened this issue Aug 5, 2019 · 2 comments
Labels

Comments

@kelvinqian00
Copy link
Contributor

I've been using Expound and overall it's a great library. However the grouping and numbering of spec errors seems to be haphazard, which is annoying when one is validating (for instance) a map with many keys predicates.

Here, we have a example keys spec:

(s/def ::foo string?)
(s/def ::bar string?)
(s/def ::qux string?)
(s/def ::ex-spec (s/keys :req-un [::foo ::bar ::qux]))

Then if I want to validate the following map:

(expound/expound ::ex-spec {:foo 1.2 :bar 123 :qux true})

I ideally want the following output (the Relevant Specs section has been removed for clarity):

-- Spec failed --------------------

  {:foo 1.2, :bar ..., :qux ...}
        ^^^

should satisfy

  string?

-- Spec failed --------------------

  {:foo ..., :bar 123, :qux ...}
                  ^^^

should satisfy

  string?

-- Spec failed --------------------

  {:foo ..., :bar ..., :qux true}
                            ^^^^

should satisfy

  string?

-------------------------
Detected 3 errors

where Expound prints out each failing spec in its own separate error message. However, what Expound actually does is print out this:

-- Spec failed --------------------

  {:foo 1.2, :bar ..., :qux ...}
        ^^^

should satisfy

  string?

or value

  {:foo ..., :bar 123, :qux ...}
                  ^^^

should satisfy

  string?

-- Spec failed --------------------

  {:foo ..., :bar ..., :qux true}
                            ^^^^

should satisfy

  string?

-------------------------
Detected 2 errors

which is not what I want. Not only do the ::foo and ::bar specs have nothing to do with each other (they are not two paths on an s/or or anything like that), but there are clearly 3, not 2, errors here.

Right now I've been using a hacky solution where I separate the original spec error map into a list of multiple error maps and using the expound method on each of them. But this comes with its own problems (it messes up the Detected Error count and overall it's just an ugly hack), so if this gets addressed that would be awesome.

@bhb bhb added the bug label Aug 5, 2019
@bhb
Copy link
Owner

bhb commented Aug 5, 2019

@kelvinqian00 Thanks for reporting this! Yes, this appears to be a bug in how Expound groups specs.

@bhb bhb mentioned this issue Oct 25, 2019
@bhb
Copy link
Owner

bhb commented Nov 25, 2019

@kelvinqian00 Thanks for reporting this and for your help with the fix! The fix is in version 0.8.0, which I've just released.

@bhb bhb closed this as completed Nov 25, 2019
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

No branches or pull requests

2 participants