This page is not created by, affiliated with, or supported by Slack Technologies, Inc.
2019-09-25
Channels
- # announcements (2)
- # babashka (22)
- # beginners (31)
- # calva (4)
- # cider (26)
- # clj-kondo (10)
- # clojure (32)
- # clojure-europe (1)
- # clojure-italy (3)
- # clojure-nl (3)
- # clojure-spec (16)
- # clojure-switzerland (5)
- # clojure-uk (25)
- # clojurescript (108)
- # clojutre (15)
- # code-reviews (3)
- # data-science (1)
- # datomic (92)
- # emacs (1)
- # fulcro (8)
- # graalvm (8)
- # jackdaw (8)
- # jobs (1)
- # jobs-discuss (1)
- # leiningen (6)
- # off-topic (56)
- # pathom (6)
- # pedestal (5)
- # re-frame (11)
- # remote-jobs (1)
- # shadow-cljs (4)
- # spacemacs (2)
- # sql (41)
- # tools-deps (7)
- # xtdb (25)
here's a sketch of wait-for-path: https://gist.github.com/sogaiu/18a81d6ba183ab7aebc19c70216c2a43
with the following script:
(println "about to wait")
;; XXX: no try in babashka / sci?
(try
(println (file/wait-for-path "/tmp/that" {:timeout 1000}))
(catch Exception e
(println e)))
(println "finished waiting")
i get:
about to wait
clojure.lang.ExceptionInfo: Could not resolve symbol: try [at line 4, column 2]
{:type :sci/error, :row 4, :col 2}
at sci.impl.utils$throw_error_with_location.invokeStatic (utils.cljc:48)
sci.impl.utils$throw_error_with_location.invoke (utils.cljc:45)
sci.impl.utils$throw_error_with_location.invokeStatic (utils.cljc:46)
sci.impl.macros$resolve_symbol.invokeStatic (macros.cljc:76)
sci.impl.macros$macroexpand_call.invokeStatic (macros.cljc:309)
sci.impl.macros$macroexpand.invokeStatic (macros.cljc:335)
sci.impl.interpreter$eval_do.invokeStatic (interpreter.cljc:58)
sci.impl.interpreter$eval_string.invokeStatic (interpreter.cljc:281)
sci.core$eval_string.invokeStatic (core.cljc:5)
...
is there some way to use try
?yes, your script will end with exit code other than 0. but I'll see what I can do with try catch finally, maybe on the plane to Helsinki today 😉
maybe it's better for wait-for-it to also not throw actually, but to return a map result
This works: lein run '(try (/ 1 0) (catch java.lang.ArithmeticException _e 1) (finally (prn "dude")))'
but GraalVM has some problems with ClassForName, so maybe I have to just make it a static set of classes you can throw
yep, this works now:
$ ./sci '(try (/ 1 0) (catch java.lang.Exception _e 1) (finally (prn "dude")))'
"dude"
1
@sogaiu try/catch/finally now works in bb master. feel free to PR any Exceptions you might need here: https://github.com/borkdude/babashka/blob/master/src/babashka/impl/exceptions.clj
Maybe it makes sense to make a namespace called wait/... with wait-for-port and wait-for-path?
also both wait/... functions could have a :default option that is returned when the waiting timed out
@borkdude i tried try/catch from bb master -- when i run the new test for it (jvm or native), it seems to work fine:
$ BABASHKA_TEST_ENV=native lein test :only babashka.main-test/try-catch-test
==== Testing native version
lein test babashka.main-test
Ran 1 tests containing 1 assertions.
0 failures, 0 errors.
and
$ lein test :only babashka.main-test/try-catch-test
==== Testing JVM version
lein test babashka.main-test
Ran 1 tests containing 1 assertions.
0 failures, 0 errors.
but when i run this script:
(try
(/ 1 0)
(catch ArithmeticException _
(println "caught an exception")))
i get:
$ ./bb examples/try-catch.clj
caught an exception
java.lang.Exception: Divide by zero [at line 1, column 1]
at sci.impl.utils$re_throw_with_location_of_node.invokeStatic (utils.cljc:63)
sci.impl.interpreter$eval_do$fn__8079.invoke (interpreter.cljc:60)
sci.impl.interpreter$eval_do.invokeStatic (interpreter.cljc:60)
sci.impl.interpreter$eval_string.invokeStatic (interpreter.cljc:301)
sci.core$eval_string.invokeStatic (core.cljc:5)
babashka.main$main$fn__8581.invoke (main.clj:231)
babashka.main$main.invokeStatic (main.clj:224)
babashka.main$main.doInvoke (main.clj:170)
clojure.lang.RestFn.applyTo (RestFn.java:137)
clojure.core$apply.invokeStatic (core.clj:665)
babashka.main$_main.invokeStatic (main.clj:262)
babashka.main$_main.doInvoke (main.clj:262)
clojure.lang.RestFn.applyTo (RestFn.java:137)
babashka.main.main (:-1)
am i doing something wrong?