Fork me on GitHub
#clojure-spec
<
2018-09-25
>
bbrinck01:09:36

I’m confused about the behavior of explain for keys* specs

bbrinck01:09:58

For a cat spec, the in refers to the to the position of the bad data before conformance

bbrinck01:09:15

but for a keys* spec, it seems to refer to the position of the bad data after conformance.

taylor01:09:05

>takes the same arguments as spec/keys and returns a regex op that matches sequences of key/values, converts them into a map, and conforms that map

bbrinck15:09:03

Ah, thanks! Although that explains the mechanism of why the two are different, I’m still not sure on the reasoning 😉

bbrinck15:09:10

i.e. why the difference in behavior is desirable

taylor15:09:09

same but that's out of my depth 🙂 I only noticed the keys* impl. would seem to cause this behavior

bbrinck15:09:14

Yep, I appreciate the link 🙂 It does indeed explain the difference. Thx!

taylor15:09:56

I suppose it may be just to make the final conform step easier, when the input has already been conformed to a map :man-shrugging:

bbrinck15:09:38

Yeah, maybe! The downside is that when I want to locate the source of the bad data, the in value is inconsistent in it’s format. In particular, it’s hard to make a custom printer like Expound be able to locate the bad data

bbrinck01:09:47

Is this a known issue? Or am I misunderstanding the intent here?

roklenarcic19:09:21

Hm if I define a spec, it requires that components are already defined. So if I have mutually recursive spec, do I just define one of the components at the top with bogus spec?

taylor19:09:52

I've run into this issue before with a recursive spec, and I think it involved a call to s/spec inside the recursive spec definition

donaldball19:09:21

I’m not sure what you mean by it requiring that components are already defined. Certainly something recursive like this works fine:

(s/def ::json
  (s/or :string string?
        :list ::json-list
        :map ::json-map))

(s/def ::json-list
  (s/coll-of ::json :kind vector?))

(s/def ::json-map
  (s/map-of ::json ::json))

nenadalm20:09:26

note that in some cases it doesn't work in cljs. e.g.: https://github.com/metosin/reitit/issues/127

richiardiandrea21:09:58

Hello folks I am having a hard time reading this spec error, I think I need some help in understanding what is wrong:

#### [{:spec #object[cljs.spec.alpha.t_cljs$spec$alpha23581], :clojure.test.check/ret {:shrunk {:total-nodes-visited 0, :depth 0, :pass? false, :result #error {:message Call to #'lambda.response/error-map did not conform to spec:
val: "Invalid body" fails at: [:args] predicate: (cat :message string? :data (? (nilable map?)))
:cljs.spec.alpha/spec  #object[cljs.spec.alpha.t_cljs$spec$alpha23551]
:cljs.spec.alpha/value  "Invalid body"
:cljs.spec.alpha/args  "Invalid body"
:cljs.spec.alpha/failure  :instrument
, :data {:cljs.spec.alpha/problems [{:path [:args], :pred (cljs.spec.alpha/cat :message cljs.core/string? :data (cljs.spec.alpha/? (cljs.spec.alpha/nilable cljs.core/map?))), :val Invalid body, :via [], :in []}], :cljs.spec.alpha/spec #object[cljs.spec.alpha.t_cljs$spec$alpha23551], :cljs.spec.alpha/value Invalid body, :cljs.spec.alpha/args Invalid body, :cljs.spec.alpha/failure :instrument}}, :result-data {:clojure.test.check.properties/error #error {:message Call to #'lambda.response/error-map did not conform to spec:

taylor21:09:59

that spec looks like it may be for a variadic function, so maybe this is related https://dev.clojure.org/jira/browse/CLJS-2793

richiardiandrea22:09:51

Let me see if that's the issue

richiardiandrea22:09:54

Well it seems like things are working with just a non-variadic function, however I am not sure my bug is related to the above

richiardiandrea23:09:27

Yep it is relate, I can reproduce it.

guy21:09:49

val: "Invalid body" fails at: [:args] predicate: (cat :message string? :data (? (nilable map?)))

guy21:09:19

to me it looks like you have a value "invalid body"

guy21:09:32

and a predicate

guy21:09:38

(cat :message string? :data (? (nilable map?)))

guy21:09:05

So maybe your predicate / spec is wrong?

guy21:09:45

{:path [:args], :pred (cljs.spec.alpha/cat :message cljs.core/string? :data (cljs.spec.alpha/? (cljs.spec.alpha/nilable cljs.core/map?)))

guy21:09:28

This is saying that the args (i guess ur function args) are being given the value Invalid body and failing your spec

guy21:09:43

https://clojuredocs.org/clojure.spec.alpha/cat Tbh I don’t really understand how this works

guy21:09:16

@richiardiandrea sorry i’m not much help haha

richiardiandrea21:09:44

that predicate is supposed to match one arguments as string and optionally a data field

guy21:09:47

what does ur (s/fdef ..) look like?

guy21:09:51

ah right

richiardiandrea21:09:12

(s/fdef error-map
  :args (s/cat :message string? :data (s/? (s/nilable map?)))
  :ret :tools.lambda.response/error-map)

taylor23:09:50

what's your defn error-map arg list look like?

richiardiandrea23:09:43

it was [message & [data]]

taylor23:09:26

it could be related to that JIRA I mentioned above about CLJS, instrumentations, and variadic functions

richiardiandrea23:09:38

Yep left a comment there, I can reproduce it here...