Fork me on GitHub
#clojure-spec
<
2018-07-23
>
roklenarcic11:07:01

I have a problem with clojure.java.jdbc.spec, namely when calling query fn which is instrumented with this spec:

(s/def ::result-set-fn (s/fspec :args (s/cat :rs (s/coll-of any?))
                                :ret  any?))
It calls my result set fn with a bunch of garbage

roklenarcic11:07:56

So when callbacks have a fspec defined, they get called with random data if they are instrumented?

gfredericks12:07:18

that's how the function is validated

gfredericks12:07:48

it is a common source of surprise

roklenarcic12:07:47

I guess i need to instrument just a specific ns

mpenet12:07:37

there are options also on instrument you can use to bypass this

mpenet12:07:45

well, to provide stubs at least

fedreg16:07:35

Is there a way (or another function) to have spec/explain return just the spec errors and not the original data as well?

samueldev16:07:45

@fedreg why not just pull the errors out of the result of spec/explain? 🤷

samueldev16:07:57

or create your own fn explain-errors that does that and use it instead 🤷

fedreg16:07:09

@samueldev I was about to do just that but then decided to check if I had missed something that already existed. Guess that’s a no… thx!

seancorfield17:07:17

@roklenarcic Yeah, I may revisit some of those fspecs in clojure.java.jdbc.spec as I get more feedback from people. As @gfredericks says, the behavior you're seeing is what clojure.spec instrumentation is intended to do, but it can be surprising at first. And of course your specific :result-set-fn may well not accept any old collection -- but given that :row-fn can transform the result set data into, essentially, an arbitrary collection of any type of element, the :result-set-fn could potentially be called on any? types... We don't have parameterized types so we can't constrain the row function to map? -> T and then the result set function to coll-of T -> U...

manutter5119:07:29

This surprised me

1. In a CLJS namespace, define a function with a name that matches a valid HTML tag (e.g. "table" or "br" or whatever)
2. Create an (s/fdef ...) spec for it.

Result: every function in that namespace now evaluates to nil.

manutter5119:07:59

Just a local fluke in my current project, or something that other people can reproduce?

manutter5119:07:12

If the latter, known issue, or new?