This page is not created by, affiliated with, or supported by Slack Technologies, Inc.
2017-02-07
Channels
- # aleph (3)
- # aws (7)
- # beginners (117)
- # boot (119)
- # cider (2)
- # cljs-dev (3)
- # clojure (193)
- # clojure-austin (1)
- # clojure-dusseldorf (4)
- # clojure-finland (5)
- # clojure-france (5)
- # clojure-italy (7)
- # clojure-portugal (1)
- # clojure-russia (204)
- # clojure-serbia (5)
- # clojure-spec (31)
- # clojure-uk (64)
- # clojurescript (288)
- # community-development (9)
- # core-async (54)
- # cursive (8)
- # datascript (18)
- # datomic (26)
- # dirac (8)
- # emacs (26)
- # figwheel (1)
- # hoplon (16)
- # jobs (2)
- # jobs-discuss (4)
- # juxt (1)
- # lein-figwheel (4)
- # leiningen (14)
- # london-clojurians (2)
- # lumo (17)
- # off-topic (44)
- # om (63)
- # om-next (2)
- # onyx (26)
- # perun (14)
- # planck (5)
- # portland-or (34)
- # proton (2)
- # protorepl (8)
- # quil (1)
- # re-frame (6)
- # reagent (16)
- # remote-jobs (4)
- # ring (7)
- # ring-swagger (10)
- # rum (1)
- # untangled (2)
I’ve got the cycle sorted, is there a way I can use it with channels, specifically transducers? So that no matter what goes on the channel all i get is an alternating sequence of say, either :a
or :b
?
@seancorfield fair enough, I’m not used to that, so it felt massive 😄
@bones cycle
is not a transducer, but a sequence generator. but you can use to-chan
to wrap it into a channel that will produce values forever
Sigh. Hi there! Me again with a real basic question. How do I add a :require
once my repl is already running?
@eslachance (require '[name.space :as alias])
in the repl
Oh that's simple. thank you!
Also to answer your question, to-chan
creates the channel and inserts a collection into it. onto-chan
takes an existing channel and pushes a collection to that existing channel
I do that often to 😛 ¯\(ツ)/¯
or if you want to know which one when conformed: (s/def ::description (s/or :string string? :nil nil?))
is there another way because when I do
(s/def ::description #(or (string? %) (nil? %)))
Now I hope I can find out why this test is failing :
{:sym paintings2.api-get/get-data-front-page}
{:spec
(fspec
:args
(cat :args (coll-of :paintings2.api-get/objectNumber))
:ret
(coll-of (and :basic/artObject :image/object))
:fn
nil),
:sym paintings2.api-get/fetch-paintings-and-images-front-page,
:failure #error {
:cause "Something wrong with the front-page"
:via
[{:type java.util.concurrent.ExecutionException
:message "java.lang.Exception: Something wrong with the front-page"
:at [java.util.concurrent.FutureTask report "FutureTask.java" 122]}
{:type java.lang.Exception
:message "Something wrong with the front-page"
:at [paintings2.api_get$get_data_front_page invokeStatic "form-init240444187305771206.clj" 8]}]
:trace
[[paintings2.api_get$get_data_front_page invokeStatic "form-init240444187305771206.clj" 8]
[paintings2.api_get$get_data_front_page invoke "form-init240444187305771206.clj" 1]
[clojure.core$comp$fn__6823 invoke "core.clj" 2542]
[clojure.core$comp$fn__6823 invoke "core.clj" 2542]
[clojure.core$pmap$fn__9385$fn__9386 invoke "core.clj" 6897]
[clojure.core$binding_conveyor_fn$fn__6772 invoke "core.clj" 2020]
[clojure.lang.AFn call "AFn.java" 18]
[java.util.concurrent.FutureTask run "FutureTask.java" 266]
[java.util.concurrent.ThreadPoolExecutor runWorker "ThreadPoolExecutor.java" 1142]
[java.util.concurrent.ThreadPoolExecutor$Worker run "ThreadPoolExecutor.java" 617]
[java.lang.Thread run "Thread.java" 745]]}}
very wierd, I changed the objectNumber from a reg-ex to a string and it looks like the old spec is still used
@roelof: did you find s/nilable
to address your description issue?
Do you any idea, how possible to put in every compojure
defroutes
(GET POST PUT) a checking system like whitelist urls or else? I need to drop to “wrap-defaults/site-defaults” part of the code or possible to do in different way? just like (function .. (defroutes..)) what is your experience which is the best? I would like to create custom cookies/session/whitelist system for my code.@seancorfield yes, I do not see any validation issues at that point
Still wierd. When I do the test one for one , I see these results :
(stest/summarize-results (stest/check 'paintings2.api-get/get-data-front-page))
{:sym paintings2.api-get/get-data-front-page}
=> {:total 1, :check-passed 1}
+(stest/summarize-results (stest/check 'paintings2.api-get/get-objectNumbers))
=> #object[clojure.core$_PLUS_ 0x1d204fe "clojure.core$_PLUS_@1d204fe"]
{:sym paintings2.api-get/get-objectNumbers}
=> {:total 1, :check-passed 1}
+(stest/summarize-results (stest/check 'paintings2.api-get/get-art-object))
=> #object[clojure.core$_PLUS_ 0x1d204fe "clojure.core$_PLUS_@1d204fe"]
{:sym paintings2.api-get/get-art-object}
=> {:total 1, :check-passed 1}
(stest/summarize-results (stest/check 'paintings2.api-get/get-data-detail-page))
{:sym paintings2.api-get/get-data-detail-page}
=> {:total 1, :check-passed 1}
(stest/summarize-results (stest/check 'paintings2.api-get/get-data-front-page))
{:sym paintings2.api-get/get-data-front-page}
=> {:total 1, :check-passed 1}
Very wierd,. When I do :
(defn test-funct
"all the test"
[]
(stest/summarize-results (stest/check 'paintings2.api-get/get-objectNumbers))
(stest/summarize-results (stest/check 'paintings2.api-get/get-art-object))
(stest/summarize-results (stest/check 'paintings2.api-get/get-data-detail-page))
(stest/summarize-results (stest/check 'paintings2.api-get/get-data-front-page))
(stest/summarize-results (stest/check 'paintings2.api-get/get-image-url')))
when I do :
(defn test-funct
"all the test"
[]
(stest/summarize-results (stest/check)))
you can find the code of the library here : https://github.com/rwobben/paintings/blob/master/src/clj/paintings2/api_get.clj
when I delete the summarize part , I see this :
:fail [(["DY-U-2" "OX-M-56" "AI-P-115" "OW-P-2508" "RV-S-925" "EM-N-87" "XJ-D-068"])],`
@roelof hard to tell without seeing all the code, but that last line you posted has strings in collections 3 levels deep [([ .. ])]
- is it possible one or more of those are not needed?
@alexmiller all the code you can find in my github code
you might get a better error message if you change the pmap
to a map
in fetch-paintings-and-images-front-page
and fetch-paintings-and-images-detail-page
it looks like the error is happening inside those pmapped functions
which is obscuring the cause
Can you run check on either of those functions and reproduce the problem?
@alexmiller then I see the same error message
can you gist the whole thing?
I can, but as I said you can find it here on github : https://github.com/rwobben/paintings/blob/master/src/clj/paintings2/api_get.clj
no, I mean the error message
@alexmiller sorry to response so late,
Here the last error message :
test-funct)
{:sym paintings2.api-get/get-objectNumbers}
{:sym paintings2.api-get/get-data-detail-page}
{:spec
(fspec
:args
(cat :args (coll-of :paintings2.api-get/objectNumber))
:ret
(coll-of (and :detail/artObject :image/object))
:fn
nil),
:sym paintings2.api-get/fetch-paintings-and-images-detail-page,
:failure #error {
:cause "Something wrong with the front-page"
:via
[{:type java.util.concurrent.ExecutionException
:message "java.lang.Exception: Something wrong with the front-page"
:at [java.util.concurrent.FutureTask report "FutureTask.java" 122]}
{:type java.lang.Exception
:message "Something wrong with the front-page"
:at [paintings2.api_get$get_data_front_page invokeStatic "api_get.clj" 128]}]
:trace
[[paintings2.api_get$get_data_front_page invokeStatic "api_get.clj" 128]
[paintings2.api_get$get_data_front_page invoke "api_get.clj" 121]
[paintings2.api_get$get_data_detail_page invokeStatic "api_get.clj" 134]
[paintings2.api_get$get_data_detail_page invoke "api_get.clj" 131]
[clojure.core$comp$fn__6823 invoke "core.clj" 2542]
[clojure.core$comp$fn__6823 invoke "core.clj" 2542]
[clojure.core$pmap$fn__9385$fn__9386 invoke "core.clj" 6897]
[clojure.core$binding_conveyor_fn$fn__6772 invoke "core.clj" 2020]
[clojure.lang.AFn call "AFn.java" 18]
[java.util.concurrent.FutureTask run "FutureTask.java" 266]
[java.util.concurrent.ThreadPoolExecutor runWorker "ThreadPoolExecutor.java" 1142]
[java.util.concurrent.ThreadPoolExecutor$Worker run "ThreadPoolExecutor.java" 617]
[java.lang.Thread run "Thread.java" 745]]}}
{:sym paintings2.api-get/get-art-object}
{:sym paintings2.api-get/get-image-url}
{:sym paintings2.api-get/get-data-front-page}
{:spec
(fspec
:args
(cat :args (coll-of :paintings2.api-get/objectNumber))
:ret
(coll-of (and :basic/artObject :image/object))
:fn
nil),
:sym paintings2.api-get/fetch-paintings-and-images-front-page,
:failure #error {
:cause "Something wrong with the front-page"
:via
[{:type java.util.concurrent.ExecutionException
:message "java.lang.Exception: Something wrong with the front-page"
:at [java.util.concurrent.FutureTask report "FutureTask.java" 122]}
{:type java.lang.Exception
:message "Something wrong with the front-page"
:at [paintings2.api_get$get_data_front_page invokeStatic "api_get.clj" 128]}]
:trace
[[paintings2.api_get$get_data_front_page invokeStatic "api_get.clj" 128]
[paintings2.api_get$get_data_front_page invoke "api_get.clj" 121]
[clojure.core$comp$fn__6823 invoke "core.clj" 2542]
[clojure.core$comp$fn__6823 invoke "core.clj" 2542]
[clojure.core$pmap$fn__9385$fn__9386 invoke "core.clj" 6897]
[clojure.core$binding_conveyor_fn$fn__6772 invoke "core.clj" 2020]
[clojure.lang.AFn call "AFn.java" 18]
[java.util.concurrent.FutureTask run "FutureTask.java" 266]
[java.util.concurrent.ThreadPoolExecutor runWorker "ThreadPoolExecutor.java" 1142]
[java.util.concurrent.ThreadPoolExecutor$Worker run "ThreadPoolExecutor.java" 617]
[java.lang.Thread run "Thread.java" 745]]}}
=> {:total 7, :check-passed 5, :check-threw 2}
maybe someone else sees why this test is failing and if I do the test alone it is a success
so you can’t reproduce it with (stest/check ‘paintings2.api-get/fetch-paintings-and-images-front-page)
?
I still see the pmap in there too in the stack trace, so doesn’t seem like you’ve removed it (or maybe need to reload)
is this right?
(s/fdef fetch-paintings-and-images-front-page
:args (s/cat :args (s/coll-of ::objectNumber))
:ret (s/coll-of (s/and :basic/artObject :image/object)))
shouldn’t it be a :ret of (s/coll-of (s/or :basic/artObject :image/object))
?
same thing on the fdef for fetch-paintings-and-images-detail-page
I think it would help to improve the exception at https://github.com/rwobben/paintings/blob/master/src/clj/paintings2/api_get.clj#L137 too
@alexmiller I could improve it but I have no idea how. I check there for two things if the id and the title are both present
I would improve the throw on line 138 to include the explain of the failure
(throw (ex-info (str "Something wrong with the front-page" id) (s/explain-data ::artObject art-object)))
then you’ll get the explanation describing the failure in your exception message above
that vector of list of vector in the input still looks fishy to me
I think this is what we are looking for :
:data #:clojure.spec{:problems [{:path [], :pred map?, :val nil, :via [:paintings2.api-get/artObject], :in []}]}
so it’s nil
and nil is not a valid artObject
get-data-front-page is being invoked with nil
so then you need to back up a step or two - fetch-paintings-and-images-front-page is being called with generated ids. ƒor each one, you’re invoking read-json-data, then get-art-object, then get-data-front-page (which receives nil)
the generator is creating random ids - I assume these ids are likely not to map to real things
when that happens, you’re getting nil and passing it down the line
so you might need to constrain the generator for the args in fetch-paintings-and-images-front-page to just objects that actually exist
another option is to use stest/instrument and the :replace option to mock your api call and force it to return something known
I think I need a way to use real ids in the specs so I need the outcome of get-object-numbers
https://clojure.org/guides/spec#_combining_code_check_code_and_code_instrument_code
that’s using instrument to mock a service call
but sounds like you were suggesting the path of modifying the spec generator
you can do that in a targeted way by supplying a custom generator for the args spec of the function call
gotta run...
@alexmiller if you bee around again. Can you help me figure out how I can stub here the service call.
I think we need to stub two services. One for fetching the ids and one for fetching the rest
Hey what does a ~
mean before a variable?
~organization
@josh_tackett is there also a ' ?
just ~organization
@josh_tackett can you post the full context? I"m guessing its inside of a semi-quote
@alexmiller how can I use that service as arguments to the get-data-front-page function ?
Hi all, I have a cljs beginner type question - I have a html form where the user can choose files. Each time they choose files, it produces a js array of js File objects. I do a (array-seq files)
to produce a clojure list of js File objects (called new-file-list
). I’d like to be able to do this (into #{} (concat existing-files-list new-file-list))
but the problem is that I can add the same File object twice. Is there any way to define a compare
fn or something to tell into #{}
about how to identify duplicate Files?