This page is not created by, affiliated with, or supported by Slack Technologies, Inc.
2022-07-28
Channels
- # asami (1)
- # aws (9)
- # babashka (16)
- # beginners (32)
- # calva (2)
- # clj-kondo (20)
- # cljdoc (6)
- # clojure (35)
- # clojure-dev (25)
- # clojure-europe (11)
- # clojure-india (1)
- # clojure-norway (2)
- # clojure-spec (26)
- # clojure-uk (1)
- # clojurescript (41)
- # conjure (3)
- # css (9)
- # cursive (18)
- # data-oriented-programming (6)
- # data-science (2)
- # emacs (47)
- # events (1)
- # fulcro (15)
- # graalvm (30)
- # gratitude (7)
- # honeysql (27)
- # inf-clojure (4)
- # introduce-yourself (2)
- # lsp (129)
- # malli (7)
- # missionary (21)
- # nbb (17)
- # off-topic (18)
- # re-frame (6)
- # releases (1)
- # shadow-cljs (120)
- # vim (7)
- # xtdb (15)
I am trying to catch a socket timeout on app startup with:
(require '[conman.core :as conman])
(try
(conman/connect! {:jdbc-url
""})
(catch java.net.SocketTimeoutException _
"Connection Timed Out"))
deps.edn
{:deps {conman/conman {:mvn/version "0.9.1"}}
It works when just using Exception
but I would like to be more specific in what I catch. I tried (:import [ SocketTimeoutExeption])
but no dice.
Stacktrace in thread.Stacktrace: https://pastebin.com/p6V9gzqx
Wait, is it because the top-level exception is com.zaxxer.hikari.pool.HikariPool$PoolInitializationException
and catch never gets to see the java.net.SocketTimeoutException
?
Using the hikari exception in catch works. Not really as specific as I'd like though. Is there a way to go down the exceptions stack in catch?
Dunno about the implementation of the Hikari code throwing the exception, but looking at the inheritance....
java.lang.Object
java.lang.Throwable
java.lang.Exception
java.lang.RuntimeException
com.zaxxer.hikari.pool.PoolInitializationException
...it would seem you cannot get more specific. Perhaps check the Hikari doc for verbose options available during development?I am trying to understand this code example from the docs for reducers/fold
:
(defn count-occurrences [words]
(r/fold
(r/monoid #(merge-with + %1 %2) (constantly {}))
(fn [m [k cnt]] (assoc m k (+ cnt (get m k 0))))
(r/map #(vector % 1) words)))
I think I've got it mostly, except for the r/monoid
expression. Do %1
and %2
correspond to the two functions below, or something else? Secondly, is constantly
providing a new map on each iteration that is then being folded into the previous state?%1
, %2
etc are a syntax for anonymous function. They stand for argument 1, argument 2 etc. There more information in the guides - https://clojure.org/guides/learn/functions#_anonymous_function_syntax
so #(merge-with + %1 %2)
is a function of two arguments in position of operation for r/monoid
I know about the positional meaning here, but I'm unsure of which positions. In my limited experience, those positions are only meaningful inside the expression they are used with.
It seems like %1
would correspond to the output of constantly {}
which is a new map. But what about %2
? Or am I mistaken?
In mathematics, a monoid is a set of values which has an operation of how to combine two values and get a new value in the set, and an identity element. The identity element e
satisfies x * e = e * x = x
for all values in the set. *
here is that “operation of how to combine two values and get a new value”.
So with that understanding, you are defining a monoid and giving the two properties that make a monoid:
• how do you combine two values: you take two maps whos values are numbers and combine the values of the same keys with +
. ie (combine {:a 1 :c 3} {:a 5})
-> {:a 6 :c 3}
which is a map whose keys are numbers and still in the set of values
• the identity element: {}
(and r/monoid
seems to want a function to return the identity element rather than just the element. And to verify that {}
is indeed an identity element, (combine {:a 1} {})
will merge the keys, there are no keys in the empty map so it will be just the value of the first map. Similarly if the identity element is first (combine {} {:a 1})
will yield back the second argument.
Is there an IFn protocol? The reason I ask is because I want to try to extend "ifn" to clr reflection methods (I am running on clr right now)
on the jvm IFn
is an interface: https://github.com/clojure/clojure/blob/master/src/jvm/clojure/lang/IFn.java
and appears the same on the cljr: https://github.com/clojure/clojure-clr/blob/master/Clojure/Clojure/Lib/IFn.cs#L29
(import [clojure.lang IFn])
((let [m method]
(reify IFn
(invoke [_ arg0]
(.Invoke method nil (into-array System.Object [arg0])))))
10)
this works (method is Console.WriteLine)
I am not sure if it will end up being useful but it is cutedeftype
will let you implement and interface, so you could use that to create something that's callable
Sean’s user-manager example repo has an https://github.com/seancorfield/usermanager-example/blob/develop/src/usermanager/model/user_manager.clj#L89 where a defrecord is callable to return the db connection. Example use case is here in the https://github.com/seancorfield/usermanager-example/blob/develop/src/usermanager/model/user_manager.clj#L133 function where it calls (db)
which is invoking an instance of that record
hey, how do I make clojure print longer stacktraces when I run stuff via lein run
? for now all the info I get is
Execution error (FileAlreadyExistsException) at sun.nio.fs.UnixCopyFile/move (UnixCopyFile.java:449).
Full report at:
/var/folders/xs/qz1q94cn4snc4xmt05l3rhmr0000gn/T/clojure-10476363638687002965.edn
there's not even a line number (except the one deep in java code)I have the following in my shell profile for convenience:
function clj-error(){
ls -tr "$TMPDIR"/clojure-* | tail -1 | xargs less
}
which I can use by just executing $ clj-error
in my terminalI'm having a bit of trouble getting started in windows. Specifically, WSL 2. I have WSL 2 working well with C/C++ to build Marlin firmware via VSCode & PlatformI/O. Which is to say, I'm relatively confident that it's working correctly. Installed clojure & lein (`sudo apt install clojure leiningen`) and that worked OK for lein new app my-app
and lein repl
with a couple packages from clojars. When I added my profiles.clj
in ~/.lein
, I get continual errors:
Retrieving cider/cider-nrepl/0.28.3/cider-nrepl-0.28.3.jar from clojars
Error loading cider.nrepl: Syntax error compiling at (cider/nrepl.clj:1:1).
My profiles.clj
looks like this:
> cat ~/.lein/profiles.clj
{:repl {:plugins [[cider/cider-nrepl "0.28.3"]
[mx.cider/enrich-classpath "1.9.0"]]}}
I had tried with version 0.28.5
first, since that looked latest, but rolled back to .3
, because that's working on my Mac. Any thoughts? What step have I missed?there should be more from the above error message as well, which would be helpful in determining what the issue is
My version:
lein -v
Leiningen 2.9.1 on Java 11.0.15 OpenJDK 64-Bit Server VM
And the full error:
Error loading cider.nrepl: Syntax error compiling at (cider/nrepl.clj:1:1).
Error loading cider.nrepl: Syntax error compiling at (cider/nrepl.clj:1:1).
Error loading cider.nrepl: Syntax error compiling at (cider/nrepl.clj:1:1).
Error loading cider.nrepl: Syntax error compiling at (cider/nrepl.clj:1:1).
Error loading cider.nrepl: Syntax error compiling at (cider/nrepl.clj:1:1).
Error loading cider.nrepl: Syntax error compiling at (cider/nrepl.clj:1:1).
Error loading cider.nrepl: Syntax error compiling at (cider/nrepl.clj:1:1).
Exception in thread "main" Syntax error compiling var at (/tmp/form-init13430373027611414889.clj:1:9257).
at clojure.lang.Compiler.analyzeSeq(Compiler.java:7114)
at clojure.lang.Compiler.analyze(Compiler.java:6789)
at clojure.lang.Compiler.analyze(Compiler.java:6745)
at clojure.lang.Compiler$InvokeExpr.parse(Compiler.java:3888)
at clojure.lang.Compiler.analyzeSeq(Compiler.java:7108)
at clojure.lang.Compiler.analyze(Compiler.java:6789)
at clojure.lang.Compiler.analyze(Compiler.java:6745)
at clojure.lang.Compiler$InvokeExpr.parse(Compiler.java:3888)
at clojure.lang.Compiler.analyzeSeq(Compiler.java:7108)
at clojure.lang.Compiler.analyze(Compiler.java:6789)
at clojure.lang.Compiler.access$300(Compiler.java:38)
at clojure.lang.Compiler$LetExpr$Parser.parse(Compiler.java:6384)
at clojure.lang.Compiler.analyzeSeq(Compiler.java:7106)
at clojure.lang.Compiler.analyze(Compiler.java:6789)
at clojure.lang.Compiler.analyze(Compiler.java:6745)
at clojure.lang.Compiler$BodyExpr$Parser.parse(Compiler.java:6120)
at clojure.lang.Compiler$FnMethod.parse(Compiler.java:5467)
at clojure.lang.Compiler$FnExpr.parse(Compiler.java:4029)
at clojure.lang.Compiler.analyzeSeq(Compiler.java:7104)
at clojure.lang.Compiler.analyze(Compiler.java:6789)
at clojure.lang.Compiler.eval(Compiler.java:7173)
at clojure.lang.Compiler.eval(Compiler.java:7166)
at clojure.lang.Compiler.eval(Compiler.java:7166)
at clojure.lang.Compiler.eval(Compiler.java:7166)
at clojure.lang.Compiler.load(Compiler.java:7635)
at clojure.lang.Compiler.loadFile(Compiler.java:7573)
at clojure.main$load_script.invokeStatic(main.clj:452)
at clojure.main$init_opt.invokeStatic(main.clj:454)
at clojure.main$init_opt.invoke(main.clj:454)
at clojure.main$initialize.invokeStatic(main.clj:485)
at clojure.main$null_opt.invokeStatic(main.clj:519)
at clojure.main$null_opt.invoke(main.clj:516)
at clojure.main$main.invokeStatic(main.clj:598)
at clojure.main$main.doInvoke(main.clj:561)
at clojure.lang.RestFn.applyTo(RestFn.java:137)
at clojure.lang.Var.applyTo(Var.java:705)
at clojure.main.main(main.java:37)
Caused by: java.lang.RuntimeException: Unable to resolve var: cider.nrepl/wrap-apropos in this context
at clojure.lang.Util.runtimeException(Util.java:221)
at clojure.lang.Compiler$TheVarExpr$Parser.parse(Compiler.java:720)
at clojure.lang.Compiler.analyzeSeq(Compiler.java:7106)
... 36 more
REPL server launch timed out.
Well, I uninstalled all the apt
tools and reinstalled with homebrew
(:man-shrugging:) and everything works again. Thanks for looking!
Yes see bubble icon with two lines in it!