metosin / schema-tools

Clojure(Script) tools for Plumatic Schema
http://metosin.github.io/schema-tools/
Eclipse Public License 2.0
107 stars 16 forks source link

`select-schema` throws NullPointerException #21

Closed stephenbrady closed 9 years ago

stephenbrady commented 9 years ago

Calling select-schema using map schemas where the key's schema is a "non-specific key" causes a NPE.

Here's the stack trace:

java.lang.NullPointerException: null
              core.clj:76 schema.spec.core/with-cache
              core.clj:90 schema.spec.core/sub-checker
           variant.clj:14 schema.spec.variant/option-step
           variant.clj:47 schema.spec.variant.VariantSpec/fn
  PersistentList.java:117 clojure.lang.PersistentList.reduce
            core.clj:6518 clojure.core/reduce
           variant.clj:45 schema.spec.variant/schema.spec.variant.VariantSpec
            coerce.clj:43 schema-tools.coerce/map-filter-matcher
            coerce.clj:60 schema-tools.coerce/or-matcher[fn]
            core.clj:2570 clojure.core/some
            coerce.clj:60 schema-tools.coerce/or-matcher[fn]
            coerce.clj:33 schema.coerce/eval15433[fn]
              core.clj:69 schema.spec.core/run-checker
            coerce.clj:30 schema.coerce/eval15433[fn]
            coerce.clj:26 schema.coerce/eval15433[fn]
            coerce.clj:92 schema-tools.coerce/coercer
           coerce.clj:103 schema-tools.coerce/coerce
           coerce.clj:101 schema-tools.coerce/coerce
             core.clj:198 schema-tools.core/select-schema
             core.clj:186 schema-tools.core/select-schema

An example schema would be this:

{(s/constrained s/Num even?) s/Any})

This is caused because the usual route of calling schema.spec.core/run-checker has been bypassed and so the params map argument is missing a cache in this line:

https://github.com/metosin/schema-tools/blob/master/src%2Fschema_tools%2Fcoerce.cljx#L43

I'll submit a pull request shortly.