Fork me on GitHub
#clojure-spec
<
2017-06-23
>
odinodin12:06:10

given a spec (obtained from ex-data of an exception thrown by inspect, i.e the :cljs.spec.alpha/spec), how can one obtain the key of that spec in the registry?

odinodin12:06:48

I want to go from spec -> the name of the fdef’ed function that failed

odinodin12:06:31

My current solution is to parse it out of the exception message, which contains “Call to #‘name-of-var did not conform to spec…“. It would be nice if instrument included the key in the ex-data, but I might be misunderstanding something here.

wilkerlucio13:06:28

@odinodin can you give please show the data you are trying to go from -> to?

wilkerlucio13:06:47

I think you might want to use (s/form) or (s/get-spec), but I'm not sure yet what you are trying to get

odinodin13:06:10

@wilkerlucio it is a spec record object, as provided by the exception thrown by instrument when a fdef’ed function is called with non-conforming input.

odinodin13:06:29

it is the spec object that (s/get-spec 'the-fdefed-var) would return as far as I can tell

wilkerlucio13:06:59

that's a long chain, hehe, I'm not sure what kind of data you are looking at, can you paste what your (ex-data) result looks like?

odinodin13:06:48

This is what (ex-data) returns:

{:cljs.spec.alpha/problems ({:some-description-of-the-problem "..."})
 :cljs.spec.alpha/spec #object[cljs.spec.alpha.t_cljs$spec$alpha56508],
 :cljs.spec.alpha/value ({:foo "bar"}),
 :cljs.spec.alpha/args ({:foo "bar"})
 :cljs.spec.alpha/failure :instrument}

odinodin13:06:15

I want to know what the :cljs.spec.alpha/spec object is referring to

odinodin13:06:02

or it would probably be more correct to say, what key points to this spec in the registry

wilkerlucio13:06:41

@odinodin gotcha, you can try calling (s/form) and (s/get-spec) on it, but I'm not sure if will work

odinodin13:06:59

I’ll try that

odinodin13:06:00

@wilkerlucio (s/form) only returns the spec as defined on the (s/fdef) var. I’ll just parse the var out from the error message instead. Anyway, thanks for your suggestions 🙂

wilkerlucio13:06:36

no problem, I'm glad you can at least work around it, maybe other people will have a better solution 😉

Alex Miller (Clojure team)14:06:36

I just haven’t had time to look at it yet

odinodin14:06:53

@alexmiller nice! Just what I was looking for :)

samueldev16:06:24

does anyone know of a library to convert clojure.spec problem explanations to more human-readable output?

bbrinck22:06:32

https://github.com/bhauman/strictly-specking seems to have some work in this direction, but I don’t think it’s a drop-in solution right now

bbrinck22:06:55

I’m also working on something now, but it’s early days and not yet ready for release

bbrinck22:06:26

(inspired by the work in strictly-specking and elm errors)

bbrinck22:06:55

I’m a bit confused by the value of “in” when using “map-of” https://gist.github.com/bhb/6f06dd07bcf5b275a7d4faf3167bfc85

bbrinck22:06:28

I searched JIRA but could not find an issue, so it may be a misunderstanding on my part

bbrinck22:06:11

@samueldev ^-- (sorry, forgot to mention you, see my comment above)

bbrinck22:06:29

@samueldev I think @ericnormand is also maybe working on something for more human-readable error messages?

samueldev22:06:04

thanks @bbrinck ! I'll do some digging with @ericnormand's work and bruces!

richiardiandrea23:06:58

I think also the above odinodin is working on something for re-frame