This page is not created by, affiliated with, or supported by Slack Technologies, Inc.
2019-03-02
Channels
- # beginners (7)
- # calva (10)
- # cider (9)
- # cljdoc (2)
- # cljsrn (10)
- # clojure (35)
- # clojure-europe (1)
- # clojure-greece (1)
- # clojure-spec (31)
- # clojure-uk (6)
- # clojurescript (3)
- # community-development (2)
- # cursive (37)
- # duct (5)
- # emacs (7)
- # fulcro (40)
- # hoplon (7)
- # off-topic (8)
- # parinfer (1)
- # quil (6)
- # re-frame (7)
- # reagent (7)
- # shadow-cljs (45)
- # sql (17)
- # tools-deps (12)
- # yada (3)
has anyone had this problem? It seems instrument
doesn’t see my fdef
s and they simply are ignored. fdef
and the function and instrument
- all in Clojurescript
@ag You've required the namespace containing the functions and the fdef
s before running instrument
?
hmm… when I eval instrument
it returns vector with speced symbols, but it doesn’t fail the spec
(I'm not sure how instrument
works in cljs so you may want to ask for help in #clojurescript if this seems to be a cljs-specific problem?)
Hard to offer more advice without seeing your code...
Also, have you tried spec's instrument
directly, to eliminate an issue with Orchestra?
I would try it in a Clojure REPL to see if you can confirm the basics work as you expect. If they do, try that exact same example in cljs if you can.
the basics… work… if I simply create a function and call it in the repl, but when it’s within the app - it doesn’t work
yeah, seems I’m right… if I call fdefed function directly - it works. But doesn’t automatically validate when used in the app
@ag Ah, I suspect the code holds onto the original function value and doesn't see the instrumented version...?
Hi. Is there any library which allows enriching the error message of the function-based spec? Default:
(defn alright? [x] false)
(s/def ::alright alright?)
(s/explain ::alright 123)
; Output: 123 - failed: alright? spec: :user/alright
With lib:
(s/def ::alright (lib/with-explanation alright? (fn [x] (str x " is not alright!")))
(s/explain ::alright 123)
; Output: 123 - failed: alright? (123 is not alright!) spec: :user/alright
maybe using the explain-printer stuff? expound would be a library to look at for an example of this
setting custom :reason
does the trick for me:
(defn with-reason-fn
"Will use (reason-fn [x]) to set :reason in explain data for the specified spec."
[spec reason-fn]
{:pre [(s/spec? spec) (ifn? reason-fn)]}
(reify s/Spec
(explain*
[_ path via in x]
(let [data (s/explain* spec path via in x)]
(map #(assoc % :reason (reason-fn x)) data)))
; Do not modify the rest of methods
(conform* [_ x] (s/conform* spec x))
(unform* [_ y] (s/unform* spec y))
(gen* [_ overrides path rmap] (s/gen* spec overrides path rmap))
(with-gen* [_ gfn] (s/with-gen* spec gfn))
(describe* [_] (s/describe* spec))))
(s/def ::alright (with-reason-fn (s/spec alright?) (fn [x] (str x " is not alright"))))
(s/explain ::alright 123)
; Output: 123 - failed: 123 is not alright spec: :user/alright
I'm trying to figure out why the following code is not working (using Clojure 1.10.0). The test fails. However, if I move the s/def definition of :n/repository after the extend-type line, it passes.
what happens if you don’t use partial but #(satisfies? % Repository)
? I’m not sure if that solved it, just curious
then it works. 🙂 you remembered my original question.
#(satisfies? Repository %)
strange, isn't it?
partial just binds the value of the var too early to see re-definitions, I think it’s related to that, although I’m not sure how it works with protocols
yeah, I'm suspecting some interplay between protocol var, auto-generated interface and closures.
is extend-type redefining something?
I'll check
I think a protocol is a var that gets redefined everytime you extend a type:
(-reset-methods (alter-var-root (:var proto) assoc-in [:impls atype] mmap))
so that explains itI see. Thanks!