This page is not created by, affiliated with, or supported by Slack Technologies, Inc.
2021-11-30
Channels
- # adventofcode (95)
- # announcements (17)
- # babashka (28)
- # beginners (107)
- # calva (34)
- # clj-kondo (7)
- # cljs-dev (20)
- # cljsrn (1)
- # clojure (95)
- # clojure-europe (41)
- # clojure-italy (3)
- # clojure-nl (5)
- # clojure-spec (7)
- # clojure-uk (4)
- # clojurescript (77)
- # cursive (7)
- # data-science (1)
- # datalog (4)
- # datomic (12)
- # events (3)
- # fulcro (32)
- # graalvm (2)
- # hugsql (19)
- # introduce-yourself (4)
- # jobs (2)
- # lsp (20)
- # membrane-term (19)
- # numerical-computing (1)
- # off-topic (8)
- # pathom (3)
- # polylith (17)
- # portal (42)
- # re-frame (7)
- # reagent (32)
- # remote-jobs (1)
- # shadow-cljs (86)
- # spacemacs (3)
- # tools-deps (52)
- # uncomplicate (1)
- # xtdb (23)
Hello! How is it possible that a nillable spec (v1) fails with NPE? This works just fine and as expected:
366 (s/def ::org-ds (s/nilable #(satisfies? % jdbc.p/Connectable)))
367 (s/conform ::org-ds nil) ;=> nil
but when I check specs using s/instrument s s/fdef
then it fails in a test with NPE:
Caused by: java.lang.NullPointerException: null
at clojure.core$instance_QMARK___5404.invokeStatic (core.clj:144)
clojure.core$find_protocol_impl.invokeStatic (core_deftype.clj:536)
clojure.core$satisfies_QMARK_.invokeStatic (core_deftype.clj:569)
clojure.core$satisfies_QMARK_.invoke (core_deftype.clj:569)
jakub.specs$fn__224908.invokeStatic (specs.clj:367)
jakub.specs/fn (specs.clj:366)
clojure.spec.alpha$spec_impl$reify__2059.conform_STAR_ (alpha.clj:923)
clojure.spec.alpha$nilable_impl$reify__2556.conform_STAR_ (alpha.clj:1839)
clojure.spec.alpha$conform.invokeStatic (alpha.clj:164)
...
clojure.spec.alpha$deriv$fn__2425.invoke (alpha.clj:1537)
...
clojure.spec.alpha$regex_spec_impl$reify__2509.conform_STAR_ (alpha.clj:1703)
...
clojure.spec.test.alpha$spec_checking_fn$conform_BANG___3024.invoke (alpha.clj:121)
Why??? 🙏✅ 1
Thank you! You were right, incorrect arg order t osatisfies? seems to have been the problem
in general, how flexible should specs be on the inputs that they accept / won't crash on. for example, in clojure.spec.alpha the kvs->map spec will crash if you pass it any non-collection:
=> (s/explain-data ::s/kvs->map [0])
nil
=> (s/explain-data ::s/kvs->map 0)
#object[Error Error: 0 is not ISeqable]
Well that function is essentially an internal spec to support s/keys* so it's only used in a coll context