This page is not created by, affiliated with, or supported by Slack Technologies, Inc.
2018-02-04
Channels
- # arachne (108)
- # beginners (16)
- # boot (48)
- # cider (34)
- # cljs-dev (12)
- # clojure (237)
- # clojure-spec (50)
- # clojure-uk (5)
- # clojurescript (8)
- # cursive (1)
- # datascript (2)
- # datomic (6)
- # defnpodcast (1)
- # emacs (1)
- # fulcro (7)
- # hoplon (1)
- # keyboards (1)
- # off-topic (22)
- # re-frame (26)
- # reagent (2)
- # specter (16)
- # unrepl (6)
- # yada (1)
Is there a way to not report errors for an argument in a s/cat
or spec only the second position of it? The first argument in my case is a JS connection object and I am not interested in seeing it when it does not validate because very verbose
@richiardiandrea If you don't care about it validating, why not spec it as any?
?
Yes that is what I am doing, but it is included as part of the error message
Oh, I see. So you want a custom error reporter instead? Have you looked at Expound?
Oh right, yes I am aware of expound. Probably I can have a custom reporter if not too tough too implement
@richiardiandrea With expound, you can customize the function that prints out your value https://github.com/bhb/expound#configuring-the-printer
See the example under “You can even provide your own function to display the invalid value.”
Although by default, parts of your data that is valid won’t be shown anyway with Expound
@richiardiandrea Here’s an example that includes a custom printer that replaces the first arg (presumably one that is verbose) with a more succinct representation https://gist.github.com/bhb/5222914641bcdd08d07b7d930e388d89
That is great thaaaanks, I am actually using expound
How do you write a spec for a map that has a namespaced keyword like :db/id
?
use a s/keys
spec, and use its :req
or :opt
to specify the individual key specs
(s/def my-spec (s/keys :req [:db/id]))
Awesome. Thanks. Thought I had to use ::db/id
for some reason
Coming soon in expound: optional human-readable error messages for predicates https://asciinema.org/a/161011
@bbrinck that’s really good, but would it be possible to add an error message to an existing spec? I’m thinking about the case where you’re trying to do this to a third-party spec whose code you don’t control
it may be too much to ask, but I think it would be better to keep the libs off each other’s toes
It’s an interesting idea … certainly you could add a an error message for a spec directly (I can add a function for this).
If you used expound/def
on an existing function, you’d probably need to overwrite the actual spec though, so as not to break the way s/def
works
Another thing to watch out for is that this won’t work unless the original spec author defined a spec for the predicate specifically
So, for instance, you won’t be able to add an error message for this instance of vector?
https://github.com/clojure/core.specs.alpha/blob/master/src/main/clojure/clojure/core/specs/alpha.clj#L16 since it’s not a spec by itself
@bbrinck yeah, I would expect the parameter in that function to be the name of a spec, not a predicate
I was looking at spec tools recently, and although I liked the functionality, I was a bit sceptical about that fact that I would have to write specs differently (using the “spec record” I think)
so that’s what struck me about your approach as well
I’d be very happy with that 🙂 does that get stored in a separate registry for expound?
@stathissideris Yes, needing to write specs differently is a fair concern here. I don’t think there’s a way to bolt this functionality onto existing specs, and even if we could, I’m not sure I’d want to
there’s been talk about spec metadata for quite a while now
…but no official solution yet
and if the consumer is using spec, it works. if they are using expound, they will get the enhanced error messages
yeah, I think it all composes a bit more nicely like that!
(for the record, I’d be happy to see something compatible go into spec, and if it did, i’d use it in expound)
looking forward to the new functionality, I have a direct use for it when you release it, so thanks for your work!
haha, that’s great, that’s the style I’m going to use
not in a hurry, but looking for ways to make the errors in my UI a bit more user-friendly
great, thank you very much, I’m going to give it a go in the next few days
so, no register-message
in the end?