babashka

https://github.com/babashka/babashka. Also see #sci, #nbb and #babashka-circleci-builds .
Daniel Stephens 2021-02-11T13:18:09.439400Z

Hi all, is there a way to get babshka to automatically handle logging of data from an ExceptionInfo exception or do I need to catch and log them myself? Some code:

(def some-map {:a 1 :b 2 :c 3})




(throw (ex-info "ABC" some-map))
The output (no mention of contents of some-map):
----- Error --------------------------------------------------------------------
Type:     clojure.lang.ExceptionInfo
Message:  ABC
Location: /home/dstephens/git/ccm/ui/i18n/./translate.clj:249:1

----- Context ------------------------------------------------------------------
245: 
246: 
247: 
248: 
249: (throw (ex-info "ABC" some-map))
     ^--- ABC

borkdude 2021-02-11T13:19:14.439900Z

hmm, I think the error output could be made nicer showing the contents of the ex-data

borkdude 2021-02-11T13:19:25.440200Z

feel free to post an issue (and optionally a PR)

1πŸ‘
borkdude 2021-02-11T13:20:09.440900Z

I'm thinking something like this:

Type:     clojure.lang.ExceptionInfo
Message:  ABC
Data: ....
maybe?

Daniel Stephens 2021-02-11T13:20:25.441300Z

okay cool, I've been meaning to understanding how babashka actually works for a while so I'll have a look. Yeah, that's sort of what I was expecting to see

borkdude 2021-02-11T13:22:35.442100Z

We could also support:

(Thread/setDefaultUncaughtExceptionHandler
 (reify Thread$UncaughtExceptionHandler
   (uncaughtException [_ thread ex]
     (log/error ex "Uncaught exception on" (.getName thread)))))
This is currently not possible, but we could make it work.

borkdude 2021-02-11T13:22:48.442300Z

feel free to post another issue about that too

borkdude 2021-02-11T13:25:30.443Z

maybe a nicer API like (set-default-uncaught-exception-handler! ...) in babashka.utils or whatever could also work

borkdude 2021-02-11T13:26:07.443400Z

Let's first add the ex-data to the error output

Daniel Stephens 2021-02-11T13:30:53.444300Z

I raised https://github.com/babashka/babashka/issues/730 for the ex-data, hope I've captured enough.

borkdude 2021-02-11T13:31:49.444600Z

thanks!

2021-02-11T13:58:35.445100Z

FYI, datascript seems to work with Graalvm now https://github.com/BrunoBonacci/graalvm-clojure/pull/34/

borkdude 2021-02-11T13:58:58.445400Z

yeah, babashka already has a datascript feature flag :)

2021-02-11T13:59:11.445700Z

ah ok cool. Missed that πŸ˜…

2021-02-11T13:59:13.445900Z

Thanks

2021-02-11T13:59:29.446300Z

β€’ I was misled by this comment Datascript does not compile at all when using clojure 1.10.

2021-02-11T13:59:39.446800Z

In the other graalvm-clojure repo

borkdude 2021-02-11T13:59:44.447Z

are there any recent improvements for this btw? last time I tried it, it really took a long time and the binary was huge

2021-02-11T14:00:15.447400Z

du -h target/datascript
 28M	target/datascript
Didn’t take too long

2021-02-11T14:00:43.448100Z

maybe it is because of the reflect-config trick. Could be made smaller i guess

borkdude 2021-02-11T14:01:44.449400Z

ok, maybe try again then by updating the feature flag. @jeroenvandijk have you seen this btw? https://yyhh.org/blog/2021/02/writing-c-code-in-javaclojure-graalvm-specific-programming/ a durable datascript, we can make a pod out of this

2021-02-11T14:02:36.449800Z

ah no i haven’t. Will check it out

2021-02-11T14:02:42.450Z

Thanks

2021-02-11T14:08:41.450700Z

Really cool that it’s posssible. Will stay away from C myself for now πŸ˜…

borkdude 2021-02-11T14:09:08.451100Z

yes. soon we will have a sqlite-ish pod but then based on datalog, how cool :)

borkdude 2021-02-11T14:10:06.451900Z

the author is now working in a CLI version first. maybe, if he's open to it, I can add pod support to that

2021-02-11T14:10:42.452300Z

Super nice πŸ™‚

holmdunc 2021-02-11T21:04:58.454100Z

for babashka.fs , is there some criteria for what to implement, and what not to implement, from the inspiration libs?

borkdude 2021-02-11T21:12:28.454400Z

@duncan540 dunno - what do you have in mind?

holmdunc 2021-02-11T21:16:02.455500Z

Something like expanding ~ in path strings to the home directory, I guess is a shell thing and not a Java thing. Handy though

borkdude 2021-02-11T21:16:41.456100Z

yeah, I think such things could be handy, but I've never personally needed it. can you give an example when one would need this in a clojure program?

borkdude 2021-02-11T21:17:35.457300Z

by not having this, people will maybe write more cross-OS friendly code, like (fs/path (System/getProperty "user.home"))

holmdunc 2021-02-11T21:17:47.457600Z

If I write some script for a personal automation task, I don't want to hardcode my username in the script

borkdude 2021-02-11T21:18:42.457900Z

$ bb -e '(System/getProperty "user.home")'
"/Users/borkdude"

holmdunc 2021-02-11T21:19:33.458700Z

yep that works. I guess it's just a question of how much of a "light touch" writing Bash-style scripts in bb aims to have

borkdude 2021-02-11T21:20:57.459700Z

I think adding a home function that does the above is still good

borkdude 2021-02-11T21:21:07.460Z

since not all people might know how this works in Clojure / JVM

holmdunc 2021-02-11T21:21:19.460200Z

I remember we talked about a "light" way too have the equivalent of Bash set -e mode, and you came up with this nice macro:

(defmacro $$
  [& args]
  `(let [proc ^{:inherit true :dir fs/*cwd*} (child/$ ~@args)]
     (child/check proc)
     nil))

borkdude 2021-02-11T21:22:11.460400Z

(brb)

holmdunc 2021-02-11T21:26:22.460900Z

The clj-commons/fs library has (fs/expand-home "~/path/to/something"). That's like Python's os.path.expanduser("~/path/to/something") and obviously it just happens natively in Bash

borkdude 2021-02-11T21:39:49.462300Z

and this should also work on Windows while "~" isn't a thing there? why not just (fs/path (fs/home) "foo" "bar")? This is even more preferable than writing hard-coded file separators

borkdude 2021-02-11T21:41:34.463600Z

maybe a function that will parse a unix shell path to a normal fs path could be nice though. So ~/path/to/something will even work on Windows

borkdude 2021-02-11T21:41:55.464Z

(I'm thinking out loud as you can tell)

holmdunc 2021-02-11T21:42:32.464700Z

yep that true, writing paths as a single string is just a hard habit to break after writing a ton of Bash over the years

borkdude 2021-02-11T21:49:26.466900Z

This is number one: https://github.com/babashka/fs/issues/12 The other one needs more hammock time maybe. Is ~ the only thing to expand? Are there other things that need expansion? Env vars?

holmdunc 2021-02-11T21:52:43.469300Z

The deluxe version of ~ that I have a hunch hardly anyone knows exists is that you can put another user's name after the tilde. So ~alice/path/to/something. Env vars would certainly be useful for writing Bash style scripts. I haven't personally noticed the lack of them though. ~ is equivalent to ${HOME} I guess.

borkdude 2021-02-11T21:55:06.470500Z

I'll just make an issue about this and then we'll think about it some more. People can react there so we can see if more people want this. My hunch currently is that this is fairly easy to do using a custom defined function

holmdunc 2021-02-11T21:55:36.470800Z

Cool - thank you for considering it!

borkdude 2021-02-11T21:57:55.471Z

https://github.com/babashka/fs/issues/13

2021-02-11T22:00:55.472500Z

Hey πŸ‘‹:skin-tone-2: I'm looking to run cljfmt in babashka; which needs rewrite-clj. Replacing it with rewrite-cljc didn't work because it relies on clojure.lang.IMeta . Has anyone walked this path before 😬 ?

borkdude 2021-02-11T22:04:25.473900Z

I don't think that path will work, since you will also have to run all of tools.reader, etc inside babashka. Even if this would work, I don't think it would perform as good as in clojure itself, which kind of misses the purpose of using babashka for good startup time.

1
borkdude 2021-02-11T22:05:39.474700Z

Having said that, there is a cljfmt binary I think? There is also a zprint binary and the zprint binary uses sci (the same interpreter that bb uses) for configuring certain things using functions.

borkdude 2021-02-11T22:06:23.475100Z

But if there is a good use case to add clojure.lang.IMeta, you can convince me to add it

2021-02-11T22:13:00.477600Z

Thanks for the pointers. I am looking to integrate a couple of formatters in a single point of entry. But since the process will take several seconds; I might not win much by using babashka here over a lean clj project :thinking_face:

2021-02-12T13:14:41.482800Z

Besides the alternatives already suggested I would recommend https://github.com/greglook/cljstyle that has a native binary and works mostly like cljfmt with more knobs.

1
borkdude 2021-02-11T22:13:50.478300Z

Exactly. If the program already takes a few seconds in an already started JVM (with all the namespaces already loaded), it's probably better to just run it on the JVM

1
borkdude 2021-02-11T22:14:49.479Z

And if you want to optimize startup time for all of these formatters, you can compile this into a GraalVM binary later on

2021-02-11T22:15:33.479100Z

This makes sense :thumbsup::skin-tone-2: Haven't played with Graal on a first hand but this seems like a good moment πŸ™‚

borkdude 2021-02-11T22:16:06.479300Z

https://github.com/lread/clj-graal-docs is a good place to start, also the #graalvm channel

holmdunc 2021-02-11T22:17:58.480Z

zprint is an impressive program. it's quite amazing how systematic the configuration can be

2021-02-11T22:18:36.480100Z

Thanks, appreciate the help