Fork me on GitHub
#reitit
<
2018-09-26
>
Hannu Hartikainen10:09:36

I added this issue comment earlier https://github.com/metosin/reitit/issues/145#issuecomment-424610485 but I’m starting to suspect it deserves its own issue. Unfortunately I have no idea how to reproduce…

Hannu Hartikainen10:09:10

tl;dr there’s something weird happening with data-specs. Reading the code, I have no idea how a reitit :parameters definition can turn into a spec for which (ifn? spec) is false.

Hannu Hartikainen10:09:50

It’s still pretty probable I’ve just misunderstood something and this is my fault 🙂

Hannu Hartikainen12:09:02

I tried changing to normal specs (instead of data specs) and still get the same error. And it still works on my machine. Hmm.

Hannu Hartikainen12:09:29

I think you basically get Can't invoke spec with a non-function predicate when you call the output of (ds/spec my-map) directly.

Hannu Hartikainen12:09:14

Still can’t figure out how a different build environment could cause that to happen.

ikitommi12:09:44

@hannu.hartikainen you shoudn’t call the spec directly, but to use it like a spec instead:

(require '[spec-tools.data-spec :as ds])
(require '[spec-tools.core :as st])

(def spec (ds/spec ::kikka {:x int?}))

(spec {:x 1})
; CompilerException clojure.lang.ExceptionInfo: Can't invoke spec with a non-function predicate

(st/decode spec {:x 1})
; {:x 1}

(st/decode spec {:x "1"})
; :clojure.spec.alpha/invalid

(st/decode spec {:x "1"} st/string-transformer)
; {:x 1}

ikitommi12:09:37

for predicates, it can be invoked directly, so (st/spec int?) can be used like int?, but that’s kinda bonus, not an intented way. wondering if the invoking should be removed to avoid confusion…

Hannu Hartikainen15:09:43

My code doesn't invoke specs though. I just use the reitit coercion middleware, and that somehow causes a spec record to be invoked.

ikitommi18:09:17

@hannu.hartikainen could you provide a small failing sample Repo?

Hannu Hartikainen18:09:34

I'll come back to you if I find a way to do that. As I said, the uberjar works just fine except when built on our Jenkins server...

Hannu Hartikainen18:09:20

Basically if I don't get any ideas about what might be the issue, I won't have time to do it. The build+deploy cycle is slow enough that I've been already trying to find any workaround to avoid investigating this further (current idea: just don't use coercion middleware when built in CI).