Fork me on GitHub
#babashka
<
2022-07-29
>
craftybones07:07:12

babashka on Heroku: Docker or some other way?

lispyclouds10:07:22

@U8VE0UBBR afaik heroku has some particular languages support https://devcenter.heroku.com/categories/language-support and clojure seems to be only the JVM flavour. Docker would be my recommendation.

borkdude10:07:36

Now integrating #babashka-cli into bb

$ clj -M:babashka/dev -x clojure.core/identity --foo 1 --bar 2
{:foo 1, :bar 2}

borkdude10:07:43

$ cat bb.edn
{:tasks {doit (prn (exec clojure.core/identity))}}
$ clj -M:babashka/dev doit --foo --dude 2
{:foo true, :dude 2}

1
💯 1
borkdude11:07:42

Babashka 0.9.159 released, babashka tasks meets babashka CLI! https://blog.michielborkent.nl/babashka-tasks-meets-babashka-cli.html

🎉 5
mkvlr12:07:48

is -n a shorthand for —-num in this example?

$ bb -x tasks/my-function -n 1 2

borkdude12:07:04

Post updated. Please refresh

👍 1
jkrasnay12:07:13

Hrm, I’m getting an error “SHA256 mismatch” when running brew install borkdude/brew/babashka on an M2 Mac. Is this just some CI thing catching up?

jkrasnay12:07:03

λ brew install borkdude/brew/babashka
==> Downloading .
==> Downloading from 
######################################################################## 100.0%
Error: babashka: SHA256 mismatch
Expected: f4f140b5382fc11bb46808f40343a408032b5c00f3f3c2216637c17d49ce07c4
  Actual: e9243d8f107929e8079917495ee6ea86845cdfb0c00e00f4050e2fa5264dd82b
    File: /Users/john/Library/Caches/Homebrew/downloads/44000a26468468a117db36aa8ab9df092eb00b6a144e876356fa04cf57d3fc29--babashka-0.9.159-macos-aarch64.tar.gz
To retry an incomplete download, remove the file above.

1
borkdude12:07:03

Can you try again?

jkrasnay12:07:03

Still getting the same error

borkdude12:07:24

Perhaps throw away your cache

jkrasnay12:07:03

I did remove the downloaded babashka tarball. Is there anything else I should do?

jkrasnay12:07:35

Ah, running brew cleanup fixed it up. Working now. Thanks!

borkdude12:07:44

I added set -euo pipefail now to the script... bash!

viesti16:07:58

Random hack to keep the order of keys from a JSON object (had a config file read with babashka and didn't want to turn the json object to a vector): https://gist.github.com/viesti/403e3a67e2bc1add10cf3365ede510bc

borkdude16:07:30

Amazing hack :) Would you mind posting the code in a gist or so? This will help sharing it and will also not flood this channel that much ❤️

❤️ 1
viesti16:07:51

ah true, I'll change it to a gist 🙂

hlship17:07:21

A pain point I'm hitting is that when exceptions occur, there's no indication of my code at all, it's all in the sci namespaces due to interpretation; could there be a way of getting something stack-trace-like that showed which interpreted functions were invoked leading up to the exception?

borkdude17:07:56

Do you mean in the REPL?

borkdude17:07:15

On the command line you should already be seeing a stacktrace but in some cases this can also be improved

hlship17:07:10

Yes, in the REPL, haven't tried w/ command line. But I'm really happy that the Cursive support for BB is close to standard the Clojure dev experience.

borkdude17:07:13

Is this the nREPL? Ah yes, there is a known issue about it. https://github.com/babashka/babashka.nrepl/issues/42

borkdude17:07:26

It is solvable, but needs some love

lread18:07:59

Yeah, if my memory aint broken, I find this too when hitting an exception when running bb tasks. My tasks usually just invoke a -main of a bb script. If I need to debug I sometimes just invoke the script directly for a better stack trace. For example instead of bb test-doc I’ll do a bb script/test_doc.clj when debugging.

borkdude18:07:45

Hmm, please report such issues with good examples

borkdude18:07:49

They can be fixed

borkdude18:07:28

Feel free to add more to this, if your example is slightly different

lread18:07:57

Will make a todo to do.

❤️ 1
borkdude19:07:32

I'll make this a priority for next month's release

hlship20:07:15

Experience is much better as a command:

----- Stack trace --------------------------------------------------------------
clojure.lang.AFunction/1    - <built-in>
clojure.core/apply          - <built-in>
net.lewisship.bb.tasks-test - /Users/howard.lewisship/workspaces/hlship/flow/test/net/lewisship/bb/tasks_test.clj:63:1
user                        - /Users/howard.lewisship/workspaces/hlship/flow/./run-tests.clj:8:1

borkdude20:07:47

vs REPL you mean right?

borkdude20:07:00

yes, that's what the babashka.nrepl issue is about. The information is there. Just needs to be sent over

hlship20:07:09

Looking forward to it.

borkdude17:08:31

I'm now looking on this. I do have the relevant data, but I'm not sure how to make an nREPL client display that data.

borkdude08:08:59

Hmm, it seems it's not so easy because nREPL is built with the expectation of a JVM environment: https://clojurians.slack.com/archives/C17JYSA3H/p1660237346960269

hlship22:07:29

For obvious reasons, I'd like to leverage io.aviso/pretty with babashka, but that fails:

> rlwrap bb
Babashka v0.9.159 REPL.
Use :repl/quit or :repl/exit to quit the REPL.
Clojure rocks, Bash reaches.

user=> (require '[io.aviso.repl :as repl])
Could not resolve symbol: Thread$UncaughtExceptionHandler [at io/aviso/repl.clj]
user=> 

hlship22:07:15

That seems odd to me, as that's a class that should exist, right?

hlship22:07:21

The code is:

(defn uncaught-exception-handler
  "Returns a reified UncaughtExceptionHandler that prints the formatted exception to `*err*`."
  {:added "0.1.18"}
  []
  (reify Thread$UncaughtExceptionHandler
    (uncaughtException [_ _ t]
      (binding [*out* *err*]
        (printf "Uncaught exception in thread %s:%n%s%n"
                (-> (Thread/currentThread) .getName)
                (e/format-exception t))
        (flush)))))

borkdude05:07:21

Not every class is built into bb due to size but we can include this one. Please create an issue in case I forget

borkdude06:07:07

Although in this case I'm not sure if it's a good idea to override bb'a uncsught exception handler since it has its own display of the interpreter stack trace