Fork me on GitHub
#beginners
<
2015-08-21
>
escherize07:08:48

I feel like I must be missing something here, using Prismatic Schema:

(require '[schema.core :as s])
;==> nil
(def A-or-B (s/enum "A" "B")) 
;==> #'bike-messenger.schema/A-or-B
(s/defn f [ab :- A-or-B] ab)
;=> nil
(f "C")
;=> "C"
(f :a)
;=> :a

escherize07:08:04

Does this make any sense? I feel like there's something very simple that I'm missing... I've used schema like 50 times!

escherize07:08:09

(s/validate s/Num "aok") ;=> "aok"

escherize07:08:31

Any ides about where to start debugging this? Digging into the library at the moment

escherize10:08:09

I am unable to slay the schema bug

kongeor11:08:25

@escherize: Hm, I get the expected exception when trying this

escherize11:08:24

Strange indeed. I doubt a version bump will fix this, but I'll give it a try.

kongeor11:08:55

what version are you using ?

escherize11:08:47

I was on 0.4.3

escherize11:08:48

Yeah - It's pretty interesting. I'm on [prismatic/schema "0.4.4"] now, and still getting

(require '[schema.core :as s])
(s/validate s/Int "aok")
;=> "aok"

kongeor11:08:49

well, checking on 0.3.3, 0.4.3 and 0.4.4 everything works fine here

escherize12:08:35

schema.core> (set-fn-validation! false)
false
schema.core> (validate Int "a")
"a"
schema.core> (set-fn-validation! true)
true
schema.core> (validate Int "a")
"a"

escherize12:08:16

I'm gonna rest my brain for a little while...

schema.core> ((fn [i :- Int] i) "ok")
"ok"

kongeor12:08:27

I think there something very wrong with your setup 😐

escherize12:08:41

$> (s/validate s/Int "this is not an int, why god?")
"this is not an int, why god?"

kongeor12:08:37

Try to create a new project and test it there

rauh12:08:01

What do these give:

(clojure.repl/source s/Int)
(clojure.repl/source s/validate)

escherize14:08:09

$> (clojure.repl/source s/Int)
(def Int
  "Any integral number"
  (pred integer? 'integer?))
nil
$> (clojure.repl/source s/validate)
(clojure.core/defn validate
  "Throw an exception if value does not satisfy schema; otherwise, return value."
  [schema value]
  (when-let [error (check schema value)]
    (macros/error! (utils/format* "Value does not match schema: %s" (pr-str error))
                   {:schema schema :value value :error error}))
  value)
nil