This page is not created by, affiliated with, or supported by Slack Technologies, Inc.
2021-10-18
Channels
- # announcements (8)
- # aws (5)
- # babashka (69)
- # beginners (37)
- # calva (222)
- # cider (10)
- # clj-commons (8)
- # clj-kondo (69)
- # cljdoc (5)
- # clojure (62)
- # clojure-dev (23)
- # clojure-europe (37)
- # clojure-italy (2)
- # clojure-nl (6)
- # clojure-sg (6)
- # clojure-uk (5)
- # clojurescript (25)
- # clojureverse-ops (12)
- # conjure (1)
- # cursive (1)
- # fulcro (9)
- # gorilla (1)
- # graalvm (6)
- # graphql (1)
- # gratitude (1)
- # honeysql (7)
- # introduce-yourself (4)
- # jobs (1)
- # kaocha (9)
- # keyboards (4)
- # leiningen (8)
- # lsp (21)
- # malli (9)
- # music (3)
- # nextjournal (17)
- # nrepl (6)
- # off-topic (10)
- # pathom (12)
- # portal (25)
- # reagent (8)
- # releases (1)
- # specter (1)
- # xtdb (1)
Hey, any recommendations on how to stub error http responses from clj-http
. I’m currently using conjure
to stub successful responses but need errors to hit for example this 403 block
(try+
(client/get "")
(catch [:status 403] {:keys [request-time headers body]}
(log/warn "403" request-time headers)))
if it's for running some tests, you could use with-redefs
to temporarily change the definition of client/get
?
Thats what conjure does. I’m trying to figure what an error value looks like
Haha, I’ve just been pointed in that direction. Cheers, trying now 🤞
I’ve used wiremock frequently from Java but thought there might something less ‘heavy’
Hi guys. How do you feel about redisson vs other redis clients in clojure land? I am in choosing a redis client which shall have rich functionalities such as redis stream, distributed lock, etc (I don’t mind implementing the features with the client thought).
We a we aren't super heavy redis users at work, some key value stuff, some pubsub stuff, and redisson worked just fine, but the big reason we moved away was it was a long term maintenance headache because it depends on both netty and Jackson, two big complicated common java dependencies, so it often conflicted with other java libraries
We're just using jedis now, which is more minimal, but like I said we don't use a ton of features
Is there a way to core.match
on a list?
(match ['(1 2)]
[(a b)]
a)
;; Invalid list syntax b in (a b) ...
I feel like I am missing something obvious but I’m not seeing it in the wiki.Ah thanks @borkdude! I was just reading the :seq
docs and getting confused by the extra nesting. That minimal example helps.
Hi there, what is the best way to store an ex-info
on file and then read it back in Clojure code?
I have tried with Throwable->map
and edn/read-string
but that throws an exception to me:
No dispatch macro for: "
Execution error at nrepl.middleware.interruptible-eval/evaluate$fn$fn (interruptible_eval.clj:87).
...
@richiardiandrea it seems you have written a regex to EDN but EDN doesn't support Clojure regex notation
Not sure about regexes, what I am doing is
(spit (io/file filename) (Throwable->map ex-info))
and then
(edn/read-string filename)
What I'm saying is that your error is likely the result of writing a regex to the file.
user=> (clojure.edn/read-string (pr-str #"foo"))
Execution error at user/eval1 (REPL:1).
No dispatch macro for: "
ok weird, I don't think I have control over the ex-info
map
btw if you really need to read regexes as edn, you can use edamame for this which optionally supports it
I think it's clara rules printing out regexes
user=> (def m {:a (Object.) :b #"foo"})
#'user/m
user=> (pr-str m)
"{:a #object[java.lang.Object 0x2a50b32d \"java.lang.Object@2a50b32d\"], :b #\"foo\"}"
user=> (e/parse-string (pr-str m) {:readers (fn [tag] identity) :regex true})
{:a [java.lang.Object 709931821 "java.lang.Object@2a50b32d"], :b #"foo"}
@borkdude is the above edamame
only or clojure as well? Sorry got confused 😄
ok thanks for confirming
edamame
's
(-> file-path slurp (e/parse-string {:readers (constantly identity) :regex true}))
Works like a charm on these logs. Thanks @borkdude.
For the future ones I am thinking of pre-processing but your parser really helped here.
ok, would pr-str
help then?
Execution error at nrepl.middleware.interruptible-eval/evaluate$fn$fn
is not a string that Throwable->map produces, so it seems like what you are trying to read was not produced by Throwable->map
exoscale/ex has something like that, based on datafy. But it's assumed everything in ex-data is serializable and the ex-cause is intentionally left out
user=> (clojure.edn/read-string (pr-str (Throwable->map (Exception.))))
{:via [{:type java.lang.Exception, :at [user$eval5 invokeStatic "NO_SOURCE_FILE" 1]}], :trace [[user$eval5 invokeStatic "NO_SOURCE_FILE" 1] [user$eval5 invoke "NO_SOURCE_FILE" 1] [clojure.lang.Compiler eval "Compiler.java" 7181] [clojure.lang.Compiler eval "Compiler.java" 7136] [clojure.core$eval invokeStatic "core.clj" 3202] [clojure.core$eval invoke "core.clj" 3198] [clojure.main$repl$read_eval_print__9112$fn__9115 invoke "main.clj" 437] [clojure.main$repl$read_eval_print__9112 invoke "main.clj" 437] [clojure.main$repl$fn__9121 invoke "main.clj" 458] [clojure.main$repl invokeStatic "main.clj" 458] [clojure.main$repl_opt invokeStatic "main.clj" 522] [clojure.main$main invokeStatic "main.clj" 667] [clojure.main$main doInvoke "main.clj" 616] [clojure.lang.RestFn invoke "RestFn.java" 397] [clojure.lang.AFn applyToHelper "AFn.java" 152] [clojure.lang.RestFn applyTo "RestFn.java" 132] [clojure.lang.Var applyTo "Var.java" 705] [clojure.main main "main.java" 40]]}
user=>
Got it, it seems then something in the ex-data
is not serializable, thanks everybody
(ex-info "Exception caught while running the rule engine."
{:action action
:tree root}
exception)
if you are writing to a file, can you just go look at the file to see what's in there?
Yep I definitely can, I was not sure it was in the data... No dispatch macro for: "
was not really hinting at that
that's the reader finding #"
- the leading #
is a character in the reader indicating a dispatch macro, and #"
is not in the reader table
or maybe that's something hard to print that's showing up in that way, but it's something like that
Oh thanks Alex that's why sounds good
the EdnReader dispatch does not support #"" so if you try to read that in edn, that's what you'll get
user=> (clojure.edn/read-string "#\"abc\"")
Execution error at user/eval3 (REPL:1).
No dispatch macro for: "
edamame
's
(-> file-path slurp (e/parse-string {:readers (constantly identity) :regex true}))
Works like a charm on these logs. Thanks @borkdude.
For the future ones I am thinking of pre-processing but your parser really helped here.
is there a good way to spec a comma separated list of values in a string?
(s/def ::valid-dbs
(fn [s]
(let [dbs (into #{} (map str/trim) (str/split s #","))]
(and (seq dbs)
(every? #{"h2" "mysql" "mariadb" "postgresql"} dbs)))))
Is there a way to conform to the split string and then use a traditional (s/def ::db-types #{"h2" ...})
?Any predicate function can be a spec
Beyond that, you need to also consider whether unforming and gen are important to you
In general I would caution against doing too much coercion at the same time as validation
We just validate. And i'm looking for the best error message.
"h2,mysqll" - failed: (fn [s] (let [dbs (into #{} (map trim) (split s #","))] (and (seq dbs) (every? #{"mysql" "postgresql" "h2" "mariadb"} dbs)))) in: [:preConditions 0 :dbms :type] at: [:preConditions :dbms :type] spec: :change-set.common/valid-dbs
The function goes in the failure message and the errors for
(s/explain #{:a :b} :c)
:c - failed: #{:b :a}
are a bit more clear