No, you're not missing anything. I've run into the same issue. I see you've found the related JIRA issue, but for those who haven't it's https://dev.clojure.org/jira/browse/CLJ-2192
> So the thing is that if you see a problem in [::k 1] you don't know if its the ::k value, or the value is a sequence and the problem is its element at pos 1. Yes, you're correct, this is ambiguous right now. In Expound (https://github.com/bhb/expound) I have some code that tries to determine which case it is, based upon some heuristics, but I'm sure there are cases in which I'll get it wrong. There are two other interesting related cases I've run into related to the `:in` path. First, there is the case where the key is wrong, not the value: (s/def ::spec-1 (s/map-of keyword? int?)) (-> (s/explain-data ::spec-1 {"foobar" 5}) :clojure.spec.alpha/problems first :in) ;; ["foobar" 0] This is also ambiguous in the way you've noted above, but it's not clear how to construct this path - how do we "point to" a key of a map? Second, there is the case where we want to use 'coll-of' with a map. In this case, the `in` path is just [0] (s/def ::coll-of (s/coll-of int? :kind map?)) (-> (s/explain-data ::coll-of {"foobar" 5}) :clojure.spec.alpha/problems first :in) ;; [0] AFAICT, we don't know from looking at that path whether it means: "look up the key `0` in the map" (incorrect) or "convert the map to a sequence, then get the 0th element" (correct). Again, Expound has some heuristics to try to figure this out. Right now, this logic is buried in the (messy) internals of Expound, but I will soon be providing a cleaner set of functions that allows clients to do more with the :clojure.spec.alpha/problems, including one that will provide a `in` path that works around these issues (in most common cases). Ben On Wednesday, July 12, 2017 at 8:50:19 AM UTC-6, Juan Monetta wrote: > > Hi everyone, > > I started exploring the clojure.spec "better user errors" thing and I'm > having some trouble matching clojure.spec.alpha/problems inside > :clojure.spec.alpha/value in explain-data. > > I'm trying to understand if there is currently a way of using problem to > directly find the part of the value that is causing the issue independent of > the spec that failed. > > For example given a spec : > > (s/def ::spec-1 (s/map-of keyword? int?)) > > (-> (s/explain-data ::spec-1 {::k 8.8}) > :clojure.spec.alpha/problems > first > :in) > => [::k 1] ;; which means the problem was with the value, not the key > > but given a different spec for the same data : > > (s/def ::k int?) > (s/def ::spec-2 (s/keys :req [::k])) > > (-> (s/explain-data ::spec-2 {::k 8.8}) > :clojure.spec.alpha/problems > first > :in) > => [::k] > > So the thing is that if you see a problem in [::k 1] you don't know if its > the ::k value, or the value is a sequence and > the problem is its element at pos 1. > > Does it make sense or I'm missing something? > > I'm trying with [org.clojure/clojure "1.9.0-alpha17"] > > -- You received this message because you are subscribed to the Google Groups "Clojure" group. To post to this group, send email to clojure@googlegroups.com Note that posts from new members are moderated - please be patient with your first post. To unsubscribe from this group, send email to clojure+unsubscr...@googlegroups.com For more options, visit this group at http://groups.google.com/group/clojure?hl=en --- You received this message because you are subscribed to the Google Groups "Clojure" group. To unsubscribe from this group and stop receiving emails from it, send an email to clojure+unsubscr...@googlegroups.com. For more options, visit https://groups.google.com/d/optout.